Is there a way to dynamically ajax add elements through jquery chosen plugin?

后端 未结 8 1597
南旧
南旧 2020-12-15 06:50

I am trying to use \"Chosen\" plugin by harvest (http://harvesthq.github.com/chosen/) and it works for the static set of options I am passing. However, what I want is that w

8条回答
  •  -上瘾入骨i
    2020-12-15 07:15

    I do it simply this way and it works perfectly:

    // this variable can be filled by an AJAX call or so
    var optionsArray = [ 
        {"id": 1, "name": "foo"}, 
        {"id": 2, "name": "bar"}
    ];
    
    var myOptions = "";
    for(var i=0; i'+optionsArray[i].name+'';
    }
    
    // uses new "chosen" names instead of "liszt"
    $(".chosen-select").html(myOptions).chosen().trigger("chosen:updated");
    

提交回复
热议问题