關於 jquery select2 多個關鍵字 模糊查詢的解決方法


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>0) {
                                collection.push(group);
                            }
                        }

 

html 部分在元素上增加2個屬性,如果存在多個的場合可以根據情況修改。

做個記錄,方便碰到類似情況的朋友


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM