chosen.jquery.js 插件,如何更改搜索方式

江边老乌龟 2015-08-24 05:43:00

chosen.jquery.js 插件,如何更改搜索方式?如图,
现在只能通过<option></option>里面的值进行搜索。我想通过value或者name进行搜索
...全文
302 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
CUG_ZG 2016-10-14
  • 打赏
  • 举报
回复
考虑到英文字母搜索,然后又优化了一下:

AbstractChosen.prototype.winnow_results = function() {
            var a, b, c, d, e, f, g, h, i, j, k, l;
            for (this.no_results_clear(), d = 0, f = this.get_search_text(), a = f.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), i = new RegExp(a, "i"), c = this.get_search_regex(a), l = this.results_data, j = 0, k = l.length; k > j; j++) b = l[j],
            b.search_match = !1,
            e = null,
            this.include_option_in_results(b) && (b.group && (b.group_match = !1, b.active_options = 0), null != b.group_array_index && this.results_data[b.group_array_index] && (e = this.results_data[b.group_array_index], 0 === e.active_options && e.search_match && (d += 1), e.active_options += 1), b.search_text = b.group ? b.label: b.html, (!b.group || this.group_search) && (b.search_match = this.search_string_match(b.search_text, c) || this.search_string_match(b.value, c), b.search_match && !b.group && (d += 1), b.search_match ? (f.length && (g = this.search_string_match(b.value, c) ? (this.search_string_match(b.search_text, c)?b.search_text.search(i):0) : b.search_text.search(i), h = b.search_text.substr(0, g + f.length) + "</em>" + b.search_text.substr(g + f.length), b.search_text = h.substr(0, g) + "<em>" + h.substr(g)), null != e && (e.group_match = !0)) : null != b.group_array_index && this.results_data[b.group_array_index].search_match && (b.search_match = !0)));
            return this.result_clear_highlight(),
            1 > d && f.length ? (this.update_results_content(""), this.no_results(f)) : (this.update_results_content(this.results_option_build()), this.winnow_results_set_highlight())
        }
CUG_ZG 2016-10-14
  • 打赏
  • 举报
回复
修改chosen.jquery.js里面的函数,代码如下: 我也是遇到这个需求,然后看了一上午chosen的插件,在里面跟数据的传递,然后做了一些判断就OK了哦

AbstractChosen.prototype.winnow_results = function() {
            var a, b, c, d, e, f, g, h, i, j, k, l;
            for (this.no_results_clear(), d = 0, f = this.get_search_text(), a = f.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), i = new RegExp(a, "i"), c = this.get_search_regex(a), l = this.results_data, j = 0, k = l.length; k > j; j++) b = l[j],
            b.search_match = !1,
            e = null,
            this.include_option_in_results(b) && (b.group && (b.group_match = !1, b.active_options = 0), null != b.group_array_index && this.results_data[b.group_array_index] && (e = this.results_data[b.group_array_index], 0 === e.active_options && e.search_match && (d += 1), e.active_options += 1), b.search_text = b.group ? b.label: b.html, (!b.group || this.group_search) && (b.search_match = this.search_string_match(b.search_text, c) || this.search_string_match(b.value, c), b.search_match && !b.group && (d += 1), b.search_match ? (f.length && (g = this.search_string_match(b.value, c) ? 0 : b.search_text.search(i), h = b.search_text.substr(0, g + f.length) + "</em>" + b.search_text.substr(g + f.length), b.search_text = h.substr(0, g) + "<em>" + h.substr(g)), null != e && (e.group_match = !0)) : null != b.group_array_index && this.results_data[b.group_array_index].search_match && (b.search_match = !0)));
            return this.result_clear_highlight(),
            1 > d && f.length ? (this.update_results_content(""), this.no_results(f)) : (this.update_results_content(this.results_option_build()), this.winnow_results_set_highlight())
        }

87,955

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧