select2 3.5.3 二级下拉及搜索
select2 [3.5.3]版本
支持搜索:
JS代码,如果Group不需要勾选,goup不加id就可以了。
$(".group-select").select2({ placeholder: "Select group or member", allowClear:true, data: arr, query: function (options){ var selectedIds = options.element.select2('val'); var data = jQuery.extend(true, {}, this.data); var selectableGroups = $.map(data, function (group) { var areAllChildrenSelected = true, parentMatchTerm = false, anyChildMatchTerm = false; if (group.text.toLowerCase().indexOf(options.term.toLowerCase()) >= 0) { parentMatchTerm = true; } var i = group.children.length; while (i--) { var child = group.children[i]; if (selectedIds.indexOf(child.id) < 0) { areAllChildrenSelected = false; } if (options.term == '' || (child.text.toLowerCase().indexOf(options.term.toLowerCase()) >= 0)) { anyChildMatchTerm = true; } else if (!parentMatchTerm) { var index = group.children.indexOf(child); if (index > -1) { group.children.splice(index, 1); } } } return (!areAllChildrenSelected && (parentMatchTerm || anyChildMatchTerm)) ? group : null; }); options.callback({ results: selectableGroups }); } });
相关推荐
chongxiaocheng 2019-12-13
84483065 2016-03-22
winnie0 2015-10-08
msyndra 2015-09-15
uvyoaa 2015-01-16
xiaochuachua 2013-06-12
富贵 2013-05-06
yybb0 2018-08-09
czFive 2018-08-09
DuKeCan 2017-10-12
gamecalo 2017-05-19
83453861 2017-03-20
HotStrong 2019-04-29
81413460 2016-10-24
lxl000 2019-04-26
89387341 2019-04-25
XTUxiaoxin 2016-05-06