我在部分视图中创建了几个ListBox
es,如下所示:
@Html.ListBoxFor(m => m.Executors, executors, new { @class = "selectpicker form-control filter-selector", @title = Messages.ChooseExecutors, multiple = "" })
我在尝试取消选择所有选定项目的下一个功能:
$('select.filter-selector option:selected').prop("selected", false);
功能完美,因为它执行了一些功能。我向函数体添加了一个日志,它返回了两个选定的option
以及我选择的<div class="btn-group bootstrap-select show-tick form-control filter-selector open">
<button type="button" class="btn dropdown-toggle btn-default" data-toggle="dropdown" role="button" data-id="Statuses" title="Новое, Принято в работу" aria-expanded="true">
<span class="filter-option pull-left">Новое, Принято в работу</span> <span class="bs-caret"><span class="caret"></span></span>
</button>
<div class="dropdown-menu open" role="combobox" style="max-height: 168px; overflow: hidden; min-height: 92px;">
<ul class="dropdown-menu inner" role="listbox" aria-expanded="true" style="max-height: 156px; overflow-y: auto; min-height: 80px;">
<li data-original-index="0"><a tabindex="0" class="" data-tokens="null" role="option" aria-disabled="false" aria-selected="false"><span class="text">На проверке</span><span class="glyphicon glyphicon-ok check-mark"></span></a></li>
<li data-original-index="1"><a tabindex="0" class="" data-tokens="null" role="option" aria-disabled="false" aria-selected="false"><span class="text">Отклонено</span><span class="glyphicon glyphicon-ok check-mark"></span></a></li>
<li data-original-index="2" class="selected"><a tabindex="0" class="" data-tokens="null" role="option" aria-disabled="false" aria-selected="true"><span class="text">Новое</span><span class="glyphicon glyphicon-ok check-mark"></span></a></li>
<li data-original-index="3" class="selected"><a tabindex="0" class="" data-tokens="null" role="option" aria-disabled="false" aria-selected="true"><span class="text">Принято в работу</span><span class="glyphicon glyphicon-ok check-mark"></span></a></li>
<li data-original-index="4"><a tabindex="0" class="" data-tokens="null" role="option" aria-disabled="false" aria-selected="false"><span class="text">Возвращено на доработку</span><span class="glyphicon glyphicon-ok check-mark"></span></a></li>
<li data-original-index="5"><a tabindex="0" class="" data-tokens="null" role="option" aria-disabled="false" aria-selected="false"><span class="text">Принято</span><span class="glyphicon glyphicon-ok check-mark"></span></a></li>
<li data-original-index="6"><a tabindex="0" class="" data-tokens="null" role="option" aria-disabled="false" aria-selected="false"><span class="text">Завершено</span><span class="glyphicon glyphicon-ok check-mark"></span></a></li>
</ul>
</div>
<select class="selectpicker form-control filter-selector" id="Statuses" multiple="" name="Statuses" title="Укажите статусы" tabindex="-98">
<option value="a59f921d-93e7-4a23-b041-53fc544e7d4e">На проверке</option>
<option value="1bb61f3c-03d7-4f53-83e5-ca5e6c9fe4b7">Отклонено</option>
<option value="96110d07-d9b4-442c-9d36-55c6505ec8eb">Новое</option>
<option value="a28af5c3-27d4-487e-8d86-8386abdbebca">Принято в работу</option>
<option value="c8054a54-c252-4b89-b12c-2fe3c00c0c91">Возвращено на доработку</option>
<option value="e944d0b5-760b-4d2a-8000-70cb2033d9ca">Принято</option>
<option value="f4e97d91-b9cb-4963-838f-c86e71f8a34c">Завершено</option>
</select>
</div>
。但它不会取消选择项目,也不会在控制台中出现任何错误。
我做错了什么?
ADDED
生成的html:
{{1}}
答案 0 :(得分:0)
谢谢大家的帮助!
我找到了一个解决方案here。我不知道Bootstrap会替换$('select.filter-selector option:selected').prop("selected", false);
$('select.filter-selector.selectpicker').selectpicker('refresh');
。所以,这段代码对我有用:
{{1}}