首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何删除自动完成搜索字段中显示的文本"undefined“?

如何删除自动完成搜索字段中显示的文本"undefined“?
EN

Stack Overflow用户
提问于 2018-08-06 08:49:12
回答 1查看 151关注 0票数 0

我有一个自动补全搜索。如果没有与搜索相对应的结果,则会显示消息"No results.“。

如果用户引入了3个与任何结果都不对应的字母,它就会显示消息"No results“。

然而,它在消息"No results“的上方显示为"undefiend”。你知道怎么删除"undefiend“文本吗?

代码语言:javascript
运行
复制
$.widget( "custom.catcomplete", $.ui.autocomplete, {
    _create: function() {
        this._super();
        this.widget().menu( "option", "items", "> :not(.ui-autocomplete-category)" );
    },
    _renderMenu: function( ul, items ) {
        var that = this,

            currentCategory = "";

        $.each( items, function( index, item ) {
            var li;
            if ( item.category != currentCategory ) {
                ul.append( "<li>" + item.category + "</li>" );
                currentCategory = item.category;
            }
            li = that._renderItemData( ul, item );


            if ( item.category ) {
                li.attr( "aria-label", item.category + " : " + item.label );
            }

        });
    }
});

$("#search").catcomplete({
    source: "{{ URL::to('autocomplete-search') }}",
    minLength: 3,
    response: function(event, ui){
        if (!ui.content.length) {
            var noResult = { value:"", label:"No results." };
            ui.content.push(noResult);
        }
    },
    select: function(event, ui) {
        if(ui.item.category=="Conferences"){
            window.location.href = ui.item.url;
        }
        else{
            $.get(ui.item.url, function(result) {
                var newConferences = '';
                var placeholder = "{{route('conferences.show', ['id' => '1', 'slug' => 'demo-slug'])}}";

                $.each(result, function(index, conference) {
                    var url = placeholder.replace(1, conference.id).replace('demo-slug', conference.slug);
                    newConferences += '<div>\n' +
'                        <div class="card box-shaddow">\n' +
'                            <div class="card-body">\n' +
'                                <h5>'+conference.name+'</h5>\n' +
'                            </div>\n' +
'                    </div></div>';
                });
                $('#conferences').html(newConferences);
            }, 'json');
        }
    }
});
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51699368

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档