2016-08-20 7 views
0

私はdevbridge's Ajax autocomplete jQuery pluginを使用して検索候補を取得しています。devbridgeのAjaxオートコンプリートjQueryプラグインに "No results"というテキストを表示するには?

提案がない場合は「結果なし」というテキストを表示しようとしています。 StackOverflowで多くを検索しました。ほとんどの回答は、のパラメータを追加するよう提案しました。showNoSuggestionNotice:trueおよびnoSuggestionNotice:「結果が見つかりません」

しかし、まだ私のためには機能しません。

私は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." 
}); 
}); 
+0

http://stackoverflow.com/a/23762395/1793718 – Lucky

+0

(http://stackoverflow.com/questions/20053231 [jQueryのUIがない結果メッセージをautocomplete-ない]の可能な重複/ jquery-ui-autocomplete-no-results-message) – Lucky

+0

私はこの回答を読んだが、何の助けも得られなかった。ここでは、私は成功または応答パラメータを使用していないためです。 –

答えて

0

私はそれをバックエンドにあった、問題を解決しました。適切な形式で提案配列を配置する必要がありました。

例:

$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; 
関連する問題