Typeahead의 소스 매개 변수를 수정해야합니다. 여기
나는 내 웹 사이트에 같은 일을 구현하는 방법입니다 -
$("#typeahead").typeahead({
'source'=>function(query, process){
return $.get("URL_OF_SEARCH", {string:query}, function(data){
data = JSON.parse(data);
var list = $.map(data, function(item){
var aItem = {
id: item.id, name: item.text, picture: item.picture
};
return JSON.stringify(aItem);
});
//Till here everything was done to fetch previous results and show them
list.push({"id":"URL_OF_SEARCH/" + query ,"name":"Search for "+query, "picture":"/favicon.ico"});
//This above line adds the last row which you want to add
return process(list);
});
},
'highlighter'=>function(item){
item = JSON.parse(item);
var itm = "<div class='typeahead_wrapper'>"
+ "<img class='typeahead_photo' src='" + item.picture + "'/>"
+ "<div class='typeahead_labels'>"
+ "<div class='typeahead_primary'>" + item.name + "</div></div></div>";
return itm;
},
});
내가 목록에 사진, 이름과 링크 (ID)를 보여 3 가지를 사용했다. 이것을 구현하려면 형광펜 기능을 수정해야했습니다.
이 정보가 도움이되기를 바랍니다.
당신의 선입견 코드를 공유 할 수 있습니까? –