jQuery选择:如何搜索选项的标题
jQuery Chosen: How to search in title of option
我正在使用一个选择框与jQuery选择插件的组合。我给每个选项一个值(4位代码)和一个标题(代码的描述)。
我希望插件在标题搜索以及当我在搜索框中输入的东西。目前它只对选项的内部文本起作用。
以前有人这样做过吗?或者有人知道怎么做?
谢谢:)
我遇到了你所面临的确切问题,并设法通过操纵所选插件js库来解决它。
基本上,您需要查找带有option.html的行,因为搜索过滤器正在处理option.html.
不再只处理option.html,我们现在希望它也能使用选项的title属性进行过滤,也就是选项。title
搜索带有AbstractChosen.prototype的行。winnow_results = function() {。
这是函数中的原始代码:
option.search_text = option.group ? option.label : option.html;
if (!(option.group && !this.group_search)) {
option.search_match = this.search_string_match(option.search_text, regex);
if (option.search_match && !option.group) {
results += 1;
}
if (option.search_match) {
if (searchText.length) {
startpos = option.search_text.search(zregex);
text = option.search_text.substr(0, startpos + searchText.length) + '</em>' + option.search_text.substr(startpos + searchText.length);
option.search_text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
}
if (results_group != null) {
results_group.group_match = true;
}
} else if ((option.group_array_index != null) && this.results_data[option.group_array_index].search_match) {
option.search_match = true;
}
让我们把它改成:
option.search_text = option.group ? option.label : option.html;
if (!(option.group && !this.group_search)) {
option.search_match = this.search_string_match(option.html, regex) || this.search_string_match_title(option.title, regex);
option.search_match_title = this.search_string_match_title(option.title, regex);
if (option.search_match && !option.group) {
results += 1;
}
if (option.search_match) {
if (searchText.length) {
if (option.search_match_title) {
startpos = option.title.search(zregex);
}
else {
startpos = option.search_text.search(zregex);
text = option.search_text.substr(0, startpos + searchText.length) + '</em>' + option.search_text.substr(startpos + searchText.length);
option.search_text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
}
}
if (results_group != null) {
results_group.group_match = true;
}
} else if ((option.group_array_index != null) && this.results_data[option.group_array_index].search_match) {
option.search_match = true;
}
现在寻找下面的另一段代码:
AbstractChosen.prototype.search_string_match = function(search_string, regex) {
var part, parts, _i, _len;
if (regex.test(search_string)) {
return true;
} else if (this.enable_split_word_search && (search_string.indexOf(" ") >= 0 || search_string.indexOf("[") === 0)) {
parts = search_string.replace(/'[|']/g, "").split(" ");
if (parts.length) {
for (_i = 0, _len = parts.length; _i < _len; _i++) {
part = parts[_i];
if (regex.test(part)) {
return true;
}
}
}
}
};
在之后,您只需在中插入下面的代码:
AbstractChosen.prototype.search_string_match_title = function(search_string, regex) {
var part, parts, _i, _len;
if (regex.test(search_string)) {
return true;
}
};
相关文章:
- 任何人都可以推荐包含搜索框的选择选项
- 如何搜索长下拉选项/选择列表
- AngularJS ngOptions 搜索过滤器 - 删除重复的选择选项
- 禁用所选搜索中的某些选项
- 如何在RadSearchBox中为不同的搜索选项提供不同的空消息
- 带有javascript的扩展搜索选项
- JQgrid搜索选项未显示
- jQuery Mobile Search隐藏搜索选项
- 多个搜索选项,单个字段,通过下拉菜单js/jquery进行选择
- Mongoose - find():搜索选项中的对象不起作用
- 谷歌地图:无法在包含数据库标记的地图中添加自动搜索选项
- 向选择列表添加搜索选项
- 谷歌地图API获取位置,地点标记和搜索选项卡
- Jquery数据表搜索选项不启用排序图标
- 当字符编码不同时,从键盘搜索选项
- 通过选项文本搜索选项索引
- PHP中的高级搜索选项
- 表头不显示在导出的PDF/EXCEL,如果我在数据表中使用列搜索选项
- jQuery选择:如何搜索选项的标题
- Select2 -告诉用户是否输入了新的搜索选项