打开select2.js源文件,
找到
process=function(element, collection) {
var group;
if (element.is("option")) {
if (query.matcher(term, element.text(), element)) {
collection.push(self.optionToData(element));
}
} else if (element.is("optgroup")) {
group=self.optionToData(element);
element.children().each2(function(i, elm) { process(elm, group.children); });
if (group.children.length>0) {
collection.push(group);
}
}
};
替换为
process=function(element, collection) {
var group;
if (element.is("option")) {
var param = term.split(" ");
var flag = true;
for(var i=0;i<param.length;i++){
if (!query.matcher(param[i], element.text(), element)) {
flag = false;
break;
}
}
if(flag){
collection.push(self.optionToData(element));
}
} else if (element.is("optgroup")) {
group=self.optionToData(element);
element.children().each2(function(i, elm) { process(elm, group.children); });
if (group.children.length>0) {
collection.push(group);
}
}
};