我尝试了多种组合,但无法清除此控件。 我使用的是jquery 3.2.1,控件是Bootstrap-select v1.13.1,这里是链接 https://developer.snapappointments.com/bootstrap-select/
我想清除teamPositionFilter选项,无论何时选择多选 groupFilter在更改之前。现在它在每次更改后附加值。我可以单步执行javascript代码,但不会更改列表。
@Html.DropDownList("groupFilter", (SelectList)(@ViewBag.GroupList), new { @class = "singleselectpicker col-md-3", title = "Group:", data_header = "Select Group:" })
@Html.DropDownList("teamPositionFilter", (MultiSelectList)(@ViewBag.TeamPositionList), new { @class = "multiselectpicker col-md-3", multiple = "multiple", title = "Team Position:", data_header = "Select one or more Team Positions:" })
$(function() {
$('#groupFilter').change(function () {
var #teamPositionFilter = $('#teamPositionFilter');
#teamPositionFilter.find('option').remove();
#teamPositionFilter.selectpicker('refresh');
});
$('.singleselectpicker').selectpicker({
showTick: true,
tickIcon: 'glyphicon-pushpin',
liveSearch: true,
liveSearchStyle: 'contains',
selectOnTab: true,
showContent: true,
size: 10,
width: 'false'
});
$('.multiselectpicker').selectpicker({
actionsBox: true,
selectAllText: 'Select All',
deselectAllText: 'Deselect All',
selectedTextFormat: 'count',
showTick: true,
tickIcon: 'glyphicon-pushpin',
liveSearch: true,
liveSearchStyle: 'contains',
selectOnTab: true,
showContent: true,
size: 10,
width: 'false',
multipleSeparator: ', '
});
});
答案 0 :(得分:0)
此声明适用于单一列表:
var groupFilter = $('#groupFilter');
groupFilter.selectpicker('val', '');
groupFilter.find('option').remove();
groupFilter.selectpicker("refresh");
但我还必须来自多选列表中的
var teamPositionFilter = $('#teamPositionFilter');
teamPositionFilter.selectpicker('deselectAll');
teamPositionFilter.find('option').remove();
teamPositionFilter.find('li').remove();
teamPositionFilter.selectpicker('refresh');
答案 1 :(得分:0)
列出了一个旧问题here
要删除所选项目:
var itemSelectorOption = $('#select-id option:selected');
itemSelectorOption.remove();
$('#select-id').selectpicker('refresh');