我正在尝试了解 jquery 提及插件 jquery mentions我在插件中看到了这一部分。谁能解释这是什么意思?最后一个返回函数有什么特别的作用? 我想在匹配值的长度小于 4 时关闭自动完成下拉列表
search: function (value, event) {
var match, pos;
//&& value.length >= this.options.minChars
if (!value) {
//sel = window.getSelection();
//node = sel.focusNode;
value = this._value();
pos = Selection.get(this.element).start;
value = value.substring(0, pos);
match = this.matcher.exec(value);
if (!match || match[1].length <= this.options.minChars) {
return '';
}
this.start = match.index;
this.end = match.index + match[0].length;
this.searchTerm = match[1];
//this._setDropdownPosition(node);
}
return $.ui.autocomplete.prototype.search.call(this, this.searchTerm, event);
}
最佳答案
我解决了这个问题,因为我发现搜索项没有重置,下拉列表没有返回空值。所以我像这样更改了搜索代码。
search: function (value, event) {
var match, pos;
//&& value.length >= this.options.minChars
if (!value) {
//sel = window.getSelection();
//node = sel.focusNode;
value = this._value();
pos = Selection.get(this.element).start;
value = value.substring(0, pos);
match = this.matcher.exec(value);
if (!match ) {
return '';
}
this.start = match.index;
this.end = match.index + match[0].length;
this.searchTerm = match[1];
if (match[1].length <= this.options.minChars) {//customization: to check minChars
this.searchTerm = '';// customization: to clear autocomplete dropdown
}
this._setDropdownPosition($('.mentions')[0]);
}
return $.ui.autocomplete.prototype.search.call(this,this.searchTerm, event);
}
关于javascript - jquery提到jquery ui autocomplete,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37677682/