jQuery UI自动完成-修改问题

jQuery UI Autocomplete - Modification Issues

本文关键字:修改 问题 UI jQuery      更新时间:2023-09-26

查看jQuery UI自动完成:http://jqueryui.com/demos/autocomplete/为了满足我的要求,我遇到了一些问题。

如果你在提供的链接中查看默认列表,其中一个选项是"ActionScript",如果你键入"Sc",它会提示"ActionScript",在我的情况下,这是不合适的。

我只希望它建议"ActionScript",例如,如果用户键入:

  • A
  • Ac
  • Act
  • Acti
  • Actio
  • 行动
  • ActionS
  • ActionSc
  • ActionScr
  • ActionScri
  • ActionScrip
  • ActionScript

"ActionScript"只是一个例子,但它能说明问题。

查看jQuery UI中的建议功能自动完成代码:

_suggest: function( items ) {
        var ul = this.menu.element
            .empty()
            .zIndex( this.element.zIndex() + 1 );
        this._renderMenu( ul, items );
        // TODO refresh should check if the active item is still in the dom, removing the need for a manual deactivate
        this.menu.deactivate();
        this.menu.refresh();
        // size and position menu
        ul.show();
        this._resizeMenu();
        ul.position( $.extend({
            of: this.element
        }, this.options.position ));
        if ( this.options.autoFocus ) {
            this.menu.next( new $.Event("mouseover") );
        }
    },

我似乎找不到缩小选择范围的部分。有人能给我指正确的方向吗?我使用的是最新的稳定版本。

function hackAutocomplete(){
    $.extend($.ui.autocomplete, {
        filter: function(array, term){
            var matcher = new RegExp("^" + term, "i");
            return $.grep(array, function(value){
                return matcher.test(value.label || value.value || value);
            });
        }
    });
}
hackAutocomplete();

找到了解决问题的代码。