[英]How to display multiple selected items side by side with jquery chosen
我的腳本如下。 我通過$ .getJSON()獲得了PersonList,並且我想使用Jquery-chosen並排顯示PersonList中的所有元素。 但是僅顯示最后一項。
感謝您的幫助。
$(document).ready(function () {
$("#raporNo").on('change', function () {
var yId = $(this).val();
$.getJSON("../Ekranlar/GorevlendirilenAdliBilUzmanlariGetir", { xId: yId },
function (PersonList) {
$("#chosenDropDown2").empty();
$.each(PersonList, function (index, itemData) {
$("#chosenDropDown2").append("<option>" + itemData.Text + "</option>");
$("#chosenDropDown2").val(itemData.Text);
$("#chosenDropDown2").trigger("chosen:updated");
});
});
});
});
是否要設置所選元素的值以使用服務器返回的所有值? 下方的下拉菜單是否可以按預期獲得所有選項?
也許您需要做的就是將所有選項上的selected屬性設置為true,然后一次觸發一次更新。
$.each(PersonList, function (index, itemData) {
$("#chosenDropDown2").append("<option>" + itemData.Text + "</option>");
});
$("#chosenDropDown2 option").attr("selected", "selected");true
$("#chosenDropDown2").trigger("chosen:updated");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.