jQuery Chosen - update select list without losing selections

前端 未结 4 957
梦如初夏
梦如初夏 2021-01-13 19:36

I\'m trying to use jQuery plugin \"Chosen\"

(http://harvesthq.github.com/chosen/ and https://github.com/harvesthq/chosen)

in my project.

What I\'m

4条回答
  •  不思量自难忘°
    2021-01-13 20:30

    This will reload the selection after xhr request (refresh list) and delete the selection if the new item list not contains the earlier selected item:

    var chosenSelectedItems = $(".chosen-select").val();  
    $('select#GroupsStr').empty();
    
    $.each(xhr.ReturnValue, function (index, item) {
        var newOption = $('');
        $('select#GroupsStr').append(newOption);
    });
    
    $("select#GroupsStr").val(chosenSelectedItems).trigger("chosen:updated");
    

提交回复
热议问题