2013-08-15 16 views

Odpowiedz

10

Co powiesz na coś takiego?

$(document).ready(function() { 
    $("#search").typeahead([ 
     { 
     limit: 10, 
     remote: { 
      url: "//my.tld/gimmesomejson.php?searchuser=%QUERY", 
      filter: function(parsedResponse) { 
      var dataset = []; 
      for (i = 0; i < parsedResponse.length; i++) { 
       dataset.push({ 
       value: parsedResponse[i].value, 
       tokens: parsedResponse[i].tokens 
       }); 
      } 
      if (parsedResponse.length == 0) { 
       dataset.push({ 
       value: "No results" 
       }); 
      } 
      return dataset; 
      }, 
     }, 
     template: '<p>{{value}}</p>', 
     engine: Hogan 
     } 
    ]); 
    }); 
0

Próbowałem tego i działa dobrze dla mnie.
Tutaj pokazuję "brak wyników" za pomocą poppera bootstrap.

$('#facility_names'+id).typeahead({ 
     items: "all", 
     source : function (query, result) { 
       if (timeout) { 
        clearTimeout(timeout); 
       } 

       timeout = setTimeout(function() { 
         $.ajax({ 
        url: master_url + "/facility_name_dropdown_list", 
        method: 'POST', 
        xhrFields: { 
         withCredentials: false 
        }, 
        data: { input_query : query}, 
        success: function (data) { 
         if(Object.keys(data.facility_name).length > 0){ 
          $("#facility_names"+id).popover('destroy'); 
          result($.map(data.facility_name, function (item) { 
           return item; 
          })); 
         } 
         else{ 
          $('#facility_names'+id).popover({container: '#botdiv'+id,placement: 'top'}).popover('show'); 
          $('#facility_names'+id).attr('data-content','No result found for \"'+$("#facility_names"+id).val()+'\"').data('bs.popover').setContent(); 
          setTimeout(function() { 
           $('#facility_names'+id).popover('destroy'); 
          }, 2000); 
         } 

        } 
       }); 
       }, 300); 

     }, 
     hint: true, 
     highlight: true, 
     cache: true, 
     compression: true, 
     minLength: 3, 
     updater: function(item) { 
      var details = ""; 
       $.ajax({ 
       url: master_url + "/get_facility_name", 
       method: 'POST', 
       xhrFields: { 
        withCredentials: false 
       }, 
       data: { facility_name : item}, 
       success: function (data) { 
        console.log(data.status); 
       } 
      }); 
      return item; 
     } 
    }); 
Powiązane problemy