2013-10-12 24 views
5

çalışmıyor bu deneyin:Bootstrap typeahead güncelleyici

$('input[name=recerv_country]').typeahead({ 
    remote : { 
     url: '?country=%QUERY', 
     filter: function(data) { 
      var resultList = data.map(function (item) { 
       return item.name; 
      }); 
      return resultList; 
     } 
    }, 
    updater : function (item) { 
     //item = selected item 
     //do your stuff. 
     alert(item.name); 
     alert('foo'); 
     alert('bar'); 
     //dont forget to return the item to reflect them into input 
     return item; 
    } 
}); 

şey olmuyor, uyarılar değil görünür. Neyi yanlış yapıyorum?

cevap

4

Twitter Bootstrap 3 ile Typeahead eklentisi bırakıldı. Bootstrap, yerine https://github.com/twitter/typeahead.js'u kullanmanızı önerir. Uzak çağrı kullandığınız için typeahead.js kullanıyor görünüyorsunuz. Typeahead.js bir updater işlevi değil.

https://github.com/twitter/typeahead.js'un özel olaylar bölümünü kontrol edin. typeahead:selected ihtiyaçlarınızı karşılayacaktır.

Ayrıca bakınız: Bootstrap 3 typeahead.js, use similar functions from Bootstrap 2

7
$('input[name=recerv_country]').on('typeahead:selected', function(evt, item) { 
    alert(item.value); 
}); 
İlgili konular