2016-12-02 132 views
0

抱歉,但我沒有找到答覆..Typeahead.js獲取ID

我的問題是我無法檢索所選產品的ID。值= 0

我的代碼:

$("#recherche").typeahead({ 
    onSelect: function(item) { 
     alert(item.value); // = 0 
    }, 
    ajax: { 
     url: "/personne/autocompletation", 
     displayField: "nomComplet", 
     triggerLength: 1, 
     method: "POST", 
     dataType: "JSON", 
     preDispatch: function (query) { 
      return { 
       query: query 
      } 
     } 
    }, 
}); 

我的代碼HTML

<li class="active" data-value="0"><a href="#"><strong>C</strong>alloway</a></li> 

對不起,我的英語...

回答

0

試試這個

$("#recherche").typeahead({ 
    source: function(query, process){ 
    $.ajax({ 
     url: "/personne/autocompletation", 
     displayField: "nomComplet", 
     triggerLength: 1, 
     method: "POST", 
     dataType: "JSON", 
     success: function (data) { 
      console.log(data); 
     } 
    }); 
    } 

}) ;