Update a select via Chosen Jquery

浪尽此生 提交于 2019-12-11 07:59:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!