jquery autocomplete devbridge noSuggestionNotice不能正常工作

时间:2016-10-14 07:40:54

标签: javascript jquery search autocomplete

我有这段代码 -

$(function(){

var fruits = [
   { value: 'Apple',id: '123',  data: 'Apple' },
   { value: 'Pear', id: '543',   data: 'Pear' },
   { value: 'Carrot', id: '123', data: 'Carrot' },
   { value: 'Cherry', id: '234', data: 'Cherry' },
   { value: 'Banana', id: '543', data: 'Banana' },
   { value: 'Radish', id: '3423', data: 'Radish' }
];

  $("#autocomplete").autocomplete({
        lookup: fruits,
        showNoSuggestionNotice:true,
        noSuggestionNotice:"No Result found",
        onSelect: function (suggestion) {
          alert('You selected: ' + suggestion.value + ', ' + suggestion.data);
        },
  });
});

在上面的代码中,当没有任何建议时,noSuggestionNotice无效。

1 个答案:

答案 0 :(得分:0)

请检查API文档。 noSuggestionNotice可能不包含在自动完成功能中,当它是一个单独的插件时可用。 http://api.jqueryui.com/autocomplete/#entry-examples

请使用此代码 http://jsbin.com/nugovolowi/edit?html,js,output



    $( document ).ready(function() {
     var fruits = [
       { value: 'Apple',id: '123',  data: 'Apple' },
       { value: 'Pear', id: '543',   data: 'Pear' },
       { value: 'Carrot', id: '123', data: 'Carrot' },
       { value: 'Cherry', id: '234', data: 'Cherry' },
       { value: 'Banana', id: '543', data: 'Banana' },
       { value: 'Radish', id: '3423', data: 'Radish'}
    ];

      $("#mydiv").autocomplete({
            source: fruits,
            onSelect: function (suggestion) {
              alert('You selected: ' + suggestion.value + ', ' + suggestion.data);
            },
            response: function(event, ui) {
                // ui.content is the array that's about to be sent to the response callback.
                if (ui.content.length === 0) {
                    $("#empty-message").text("No results found");
                } else {
                    $("#empty-message").empty();
                }
            }
      });
    });

    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width">
      <title>JS Bin</title>
    </head>
    <body>
    <script src="https://code.jquery.com/jquery-1.11.3.js"></script>
    <link href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" />
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    <input type="text" id="mydiv"/>
      <div id="empty-message"></div>
    </body>
    </html>
&#13;
&#13;
&#13;