gpt4 book ai didi

javascript - 动态 MVC 多部分下拉列表

转载 作者:行者123 更新时间:2023-11-28 04:47:39 26 4
gpt4 key购买 nike

我正在尝试创建一个动态多选下拉列表。下面的代码不起作用

  <div class="form-group">
@Html.Label("Solutions", htmlAttributes: new { @class = "control-label col-md-4" })
<div class="col-md-8">
@Html.DropDownListFor(model => model.SolutionList, new SelectList(new List<SelectListItem>(), "Value", "Text"), new { multiple = "true", @class = "form-control list-group-active-color", Style = "width:100% !important", onchange = "OnGetSolutionsChange(this)" })
@Html.ValidationMessageFor(model => model.SolutionList, "", new { @class = "text-danger" })
</div>
</div>

var 解决方案选项 = "";

    jQuery(result).each(function () {
solutionOptions += "<label><input type='checkbox' name='categories' value='" + this.Value + "'>" + this.Text + "</input></label>";
});
target.append(solutionOptions);
target.multiselect('rebuild')

最佳答案

这解决了我的问题:

jQuery("#SolutionList").multiselect('destroy');
jQuery("#SolutionList").multiselect();

jQuery(result).each(function () {
$("#SolutionList").append('<option value="' + this.Value + '">' + this.Text + '</option>').multiselect('rebuild');
});

关于javascript - 动态 MVC 多部分下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43217787/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com