2013-10-12 11 views
5

provo questo:Bootstrap typeahead updater non funziona

$('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; 
    } 
}); 

Non succede nulla, non appare avvisi. Cosa faccio di sbagliato?

risposta

4

Con Twitter Bootstrap 3 il plug-in Typeahead è stato eliminato. Bootstrap consiglia di utilizzare https://github.com/twitter/typeahead.js in sostituzione. Sembra che tu usi typeahead.js perché usi la chiamata remota. Typeahead.js non ha una funzione di aggiornamento.

Controllare la sezione eventi personalizzati di https://github.com/twitter/typeahead.js. typeahead:selected forse si adatta alle tue esigenze.

Consulta anche: Bootstrap 3 typeahead.js, use similar functions from Bootstrap 2

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