Commit 2f937ccd675783d5d8d43f320d9a2027274a4b9b
1 parent
aac9a320
支持拼音搜索的select2
Showing
1 changed file
with
29 additions
and
0 deletions
src/main/resources/static/assets/js/common.js
| @@ -84,6 +84,35 @@ function putFormData(json, fId){ | @@ -84,6 +84,35 @@ function putFormData(json, fId){ | ||
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | /** | 86 | /** |
| 87 | + * 支持拼音搜索的select2 | ||
| 88 | + * @param selector | ||
| 89 | + * @param data | ||
| 90 | + */ | ||
| 91 | +function initPinYinSelect2(selector, data, cb){ | ||
| 92 | + | ||
| 93 | + $.each(data, function(){ | ||
| 94 | + this.fullChars = pinyin.getFullChars(this.text).toUpperCase(); | ||
| 95 | + this.camelChars = pinyin.getCamelChars(this.text); | ||
| 96 | + }); | ||
| 97 | + | ||
| 98 | + $.fn.select2.amd.require(['select2/compat/matcher'], function (oldMatcher) { | ||
| 99 | + $(selector).select2({ | ||
| 100 | + data: data, | ||
| 101 | + matcher: oldMatcher(function(term, text, item){ | ||
| 102 | + var upTerm = term.toUpperCase(); | ||
| 103 | + if(item.fullChars.indexOf(upTerm) != -1 | ||
| 104 | + || item.camelChars.indexOf(upTerm) != -1) | ||
| 105 | + return true; | ||
| 106 | + | ||
| 107 | + return text.indexOf(term) != -1; | ||
| 108 | + }) | ||
| 109 | + }); | ||
| 110 | + | ||
| 111 | + cb && cb(); | ||
| 112 | + }); | ||
| 113 | +} | ||
| 114 | + | ||
| 115 | +/** | ||
| 87 | * 将模块List 转换为树结构 | 116 | * 将模块List 转换为树结构 |
| 88 | * @param arr | 117 | * @param arr |
| 89 | * @returns {Array} | 118 | * @returns {Array} |