javascript - jquery提到jquery ui autocomplete

标签 javascript jquery oop jquery-ui

我正在尝试了解 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/

相关文章:

javascript - React-redux 递归渲染组件时未获取状态

javascript - 检查 div 是否存在,如果不存在 - 再次检查直到它被创建

javascript - 返回上一页

jquery - Html 链接不能与 jquery 效果结合使用

php - 将数据库值获取到对象中

JavaScript 执行从函数声明开始,而不是从 $(document).ready() 开始?

java - 打印 AJAX 成功数据?

javascript - Angular UI 可排序 - 分组

javascript - 在 &lt;script&gt;[/&lt;style&gt;] 标签之间转义 JavaScript[/CSS] : Insights on a potentially broken status quo

java - 仅用于语义的类