2016-10-14 40 views
0

我有這樣的代碼 -jQuery的自動完成devbridge noSuggestionNotice不工作

$(函數(){

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不工作,當沒有建議。

回答

0

請檢查API文檔noSuggestion當它是一個單獨的插件時,可能不包含在自動完成功能中的注意事項 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>

+0

因爲我已經把很多的努力impliment它,我不能改變整個代碼。這裏是我正在使用的原始腳本 - https://www.devbridge.com/sourcery/components/jquery-autocomplete/ –

+0

並提供了noSuggestionNotice函數。 –