對不起,如果這是一個重複的問題,但我不明白其他人的答案。我使用的是Twitter Bootstrap Ajax Typeahead插件(https://github.com/biggora/bootstrap-ajax-typeahead/),用於從來自SQL查詢的數據中搜索電子郵件。這是我使用的一個PHP文件的代碼,我使用人們的電子郵件作爲valueField和人名作爲displayField,並且效果很好。bootstrap-typeahead的顯示字段使用多個值
inputSearch.typeahead({
ajax: {
url: urlAjax + '?requete=rechercheannuaire',
displayField: "description",
valueField: "id",
triggerLength: 2,
method: "get",
loadingClass: "loading-circle",
preProcess: function(data){
if(data.type === "error")
{
return false;
}
return data.datas;
}
},
onSelect: function(data){
//alert("assez tot");
data.text = data.value;
//console.log(data);
$("#chercherinvite").val(data.text);
return data;
}
});
的問題是,我必須能夠搜索到「迪雅爾丹」以及「杜花園」,我不能找到一種方法,多值賦給displayField。如果有人能夠解釋typeahead是如何工作的,我會很感激,我不理解這些文檔。