第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用單個 ajax 調(diào)用填充多個 dropdownList

如何使用單個 ajax 調(diào)用填充多個 dropdownList

C#
哆啦的時光機 2022-11-21 16:12:38
下面的代碼生成 5 個下拉列表。@{for (int i = 0; i < 5; i++) { <tr>    <td> @Html.Editor("[" + i + "].QNo", new { htmlAttributes = new { @class = "form-control ", @type = "text",        @placeholder = " QNo", @required = "", @id = "txtQNo", @style = "width:60px;" } }) </td>    <td>&nbsp;&nbsp;&nbsp;</td>    <td> @Html.DropDownList("[" + i + "].Question", new SelectList(string.Empty, "Value", "Text"), "Select Question",        new { @class = "form-control ", @id = "Question", @style = "width:900px;" })</td>    </tr>    }  }我正在嘗試使用通過下面的 ajax 調(diào)用收到的一堆值來填充上面的 5 個下拉菜單$("#ReflectionType").on("change", function (event) {    $.ajax({        type: "post",        url: "/Question/GetQuestions",        data: { TypeId: $('#ReflectionType').val() },        datatype: "json",        traditional: true,        success: function (data) {            debugger;            $.each(data, function (index, value) {                var markup = '';                $("#Question").append('<option value="' + value.Question + '">' + value.Question + '</option>');                           });                   }    });上面的代碼片段只更新了一個下拉列表(第一個下拉菜單),它應(yīng)該更新所有五個下拉列表。
查看完整描述

1 回答

?
函數(shù)式編程

TA貢獻1807條經(jīng)驗 獲得超9個贊

@{

for (int i = 0; i < 5; i++) { <tr>

    <td> @Html.Editor("[" + i + "].QNo", new { htmlAttributes = new { @class = "form-control ", @type = "text",

    @placeholder = " QNo", @required = "", @id = "txtQNo", @style = "width:60px;" } })</td>

    <td>&nbsp;&nbsp;&nbsp;</td>

    <td> @Html.DropDownList("[" + i + "].Question", new SelectList(string.Empty,"Value", "Text"), "Select Question",

    new { @class = "form-control ", @id = "Question"+i, @style = "width:900px;" })</td>


</tr>

   }

}

這將生成唯一的 id,如下所示 Question0、Question1、Question2、Question3、Question4


$("#ReflectionType").on("change", function (event) {

$.ajax({

    type: "post",

    url: "/Question/GetQuestions",

    data: { TypeId: $('#ReflectionType').val() },

    datatype: "json",

    traditional: true,

    success: function (data) {

        debugger;

        $.each(data, function (index, value) {


            var markup = '';

            for(let j = 0; j < 5; j++){

                $("#Question"+j).append('<option value="' + value.Question + '">' + value.Question + '</option>');

           }

        });


    }

});

如我所見,您的循環(huán)正在運行 5 次迭代,您可以以相同的方式運行它并附加來自 ajax 調(diào)用的數(shù)據(jù)?;蛘吣梢允褂?starts with selector 如下


$('[id^=Question]').each(function(index,element){

 $(element).append('<option value="' + value.Question + '">' + value.Question + '</option>');

})

希望這能解決您的問題??鞓肪幋a!


查看完整回答
反對 回復(fù) 2022-11-21
  • 1 回答
  • 0 關(guān)注
  • 121 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號