jQueryで選択したプラグインと組み合わせてselectboxを使用しています。私は各オプションに値(4桁のコード)とタイトル(コードの説明)を与えました。jQuery Chosen:オプション名の検索方法
検索ボックスに何かを入力すると、プラグインでタイトルを検索することもできます。現在のところ、オプションの内部テキストのためだけに機能しています。
誰かが以前にこれをしたことがありますか、誰かがこれを行う方法を知っていますか?
感謝:)
jQueryで選択したプラグインと組み合わせてselectboxを使用しています。私は各オプションに値(4桁のコード)とタイトル(コードの説明)を与えました。jQuery Chosen:オプション名の検索方法
検索ボックスに何かを入力すると、プラグインでタイトルを検索することもできます。現在のところ、オプションの内部テキストのためだけに機能しています。
誰かが以前にこれをしたことがありますか、誰かがこれを行う方法を知っていますか?
感謝:)
私はあなたが直面している正確な問題があったし、選ばれたプラグインのJSライブラリを操作することによって、それを解決するために管理しました。
検索フィルタがoption.htmlで作業されているので基本的に、あなたはoption.htmlと行を調べる必要があります。代わりにのみoption.htmlでの作業の
、我々は今、この場合には option.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;
}
};
これは役立ちます。
[mcve](http://stackoverflow.com/help/mcve)にお読みください。 – guradio