【问题标题】:How to display "No results" text in devbridge's Ajax autocomplete jQuery plugin?如何在 devbridge 的 Ajax 自动完成 jQuery 插件中显示“无结果”文本?
【发布时间】:2016-12-27 18:30:26
【问题描述】:

我正在使用devbridge's Ajax autocomplete jQuery plugin 获取搜索建议。

当没有建议时,我试图显示“无结果”文本。 我在 StackOverflow 上搜索了很多。大多数答案建议添加参数 showNoSuggestionNotice: truenoSuggestionNotice: "No results found."

但是,它仍然对我不起作用。

我还阅读了jQuery UI autocomplete- no results message 的答案,但我认为它指的是不同的 jQuery UI 自动完成小部件,因为它的参数与我使用的不同。

代码:

$(function(){
$('#search_key').autocomplete({
    serviceUrl: WORK_ROOT+'index.php?page_key=display_search_result&mode=get_suggestions',
    paramName:'search_key',
    onSearchStart: function(q) {
                $('#search_key').autocomplete('hide');
    },
    noCache: false,
    type: 'GET',
    dataType:'json',
    onSelect: function(suggestion) {
        //arm : submit search
        searchProducts()
    },
    onHint: function (hint) {
        $('#autocomplete-ajax-x').val(hint);
    },
    showNoSuggestionNotice: true,
    noSuggestionNotice: "No results found."
});
});

【问题讨论】:

标签: jquery autocomplete


【解决方案1】:

我解决了这个问题,它在后端。需要以适当的形式排列建议数组。

例子:

$reply['suggestions'] = array();
if($result_records)
{
    $result_records = array_unique($result_records);
    foreach($result_records as $result_record)
    {
        $reply['suggestions'][] = array('value' => $result_record, 'data' => $result_record);
    }
}
echo json_encode($reply);exit; 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-30
    • 1970-01-01
    • 2014-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多