我试图理解jquery提及插件jquery提及,并且我在插件中遇到了这一部分。谁能解释这是什么意思?最后的返回函数有什么特别的作用?当匹配的值的长度小于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);
}
我解决了这个问题,因为我发现searchterm没有重置,下拉菜单没有返回空值。所以我改变了这样的搜索代码。
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);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句