问题
I have an issue with chosen.jquery.js when i try to update a list dynamically and write the code below
$(selector).trigger("chosen:updated");
it works fine, but updating only the select so the values rendered still as they are with no change
as the rendered values got from a (ul) placed in a div besides the updated select
how can i update the rendered values ?
回答1:
Added .trigger('chosen:updated');
after .append(...)
so that "select changed" now shows up in the selection box.
$('#Groups').chosen().change(function (evt, params) {
$('#Groups').append($("<option/>", {
value: "test",
text: "select changed"
})).trigger('chosen:updated');
});
$('.chosen').empty().trigger('chosen:updated');
$('#Groups').append($("<option/>", {
value: "1",
text: ""
}));
$('#Groups').append($("<option/>", {
value: "2",
text: "2"
}));
$('#Groups').append($("<option/>", {
value: "3",
text: "3"
}));
$('.chosen').trigger('chosen:updated');
Is this what you're looking for? http://jsfiddle.net/8wykf44s/2/
来源:https://stackoverflow.com/questions/32468459/update-a-select-via-chosen-jquery