0

私のスクリプトは次のとおりです。$.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");

                });                 
            });
    });
});

4

1 に答える 1

0

サーバーから返されたすべての値を使用するように、選択した要素の値を設定しますか? 下のドロップダウンは、期待どおりにすべてのオプションを取得しますか?

おそらく、すべてのオプションで selected 属性を true に設定し、選択したもので更新をトリガーするだけです。

$.each(PersonList, function (index, itemData) {
    $("#chosenDropDown2").append("<option>" + itemData.Text + "</option>");
});
$("#chosenDropDown2 option").attr("selected", "selected");true
$("#chosenDropDown2").trigger("chosen:updated");
于 2015-01-30T15:56:06.730 に答える