简体   繁体   English

jQuery自动完成:如何忽略逗号作为分隔符

[英]Jquery autocomplete: How to ignore comma as delimiter

I am currently having some trouble with the autocomplete widget from Jquery. 我目前在使用Jquery的自动完成小部件时遇到了一些麻烦。 I have a remote datasource where some of the strings (or search terms) have commas in them. 我有一个远程数据源,其中某些字符串(或搜索词)中包含逗号。 As soon as I type a comma in the input text box, the list of suggestions disappear. 在输入文本框中输入逗号后,建议列表就会消失。

To me it seems that the autocomplete widget uses comma as a delimiter. 在我看来,自动完成小部件使用逗号作为分隔符。 How can I easily ignore the comma so I can display the right result? 如何轻松忽略逗号,以便显示正确的结果?

Here is my code: 这是我的代码:

$.widget( "custom.catcomplete", $.ui.autocomplete, {
    _renderMenu: function( ul, items ) {
        var that = this,
        currentCategory = "";
        $.each( items, function( index, item ) {
            if ( item.category != currentCategory ) {
                ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
                currentCategory = item.category;
            }
            that._renderItemData( ul, item );
        });
    }
});


$(".sottendeDokumenterSearchField").catcomplete({
    source: "myURL",
    minLength: 2,
    select: function( event, ui ) {
        return processAutocompleteElSelected(event, ui);
    },
    open: function(event, ui){
        if(autoselect){
            var keyEvent = $.Event("keydown");          
            keyEvent.keyCode = $.ui.keyCode.DOWN;

            $(".sottendeDokumenterSearchField").trigger(keyEvent); 
            keyEvent.keyCode = $.ui.keyCode.ENTER; 
            $(".sottendeDokumenterSearchField").trigger(keyEvent); 
        }

        autoselect = false;
    }
});

You could try going into the jquery.autocomplete.ui JS file, and finding and removing the comma case from that code. 您可以尝试进入jquery.autocomplete.ui JS文件,然后从该代码中查找和删除逗号。 Then the field would never look for it. 然后,该领域将永远不会寻找它。 I'm not sure which version of ui or which build you are using. 我不确定您使用的是哪个版本的ui或哪个版本。

Before sending the input value to your autocomplete function, strip it from comma's with a str_replace. 在将输入值发送到自动完成功能之前,请使用str_replace将其从逗号中删除。

I'm not familiar with the autocomplete widget so I can't give any code examples, sorry. 我对自动填充小部件不熟悉,因此无法提供任何代码示例,对不起。 Hope it can still point you to the right direction though. 希望它仍然可以指出正确的方向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM