select2 只针对 元素的text()进行匹配,实际开发过程中可能会存在通过id 或者特殊编码进行 多关键字匹配。
改动了下源码:红色为改动部分。
process=function(element, collection) {
var group;
if (element.is("option")) {
// modify by yuan 2016.2.15
if (query.matcher(term, element.text(), element) ||
query.matcher(term, element.attr("data-help1"), element) ||
query.matcher(term, element.attr("data-help2"), 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>) {
collection.push(group);
}
}
html 部分在元素上增加2个属性,如果存在多个的场合可以根据情况修改。
做个记录,方便碰到类似情况的朋友