1
typeahead의 정규 표현식 함수를 사용하여 검색 결과가 반환되지 않는지 확인하려고합니다. 결과가 나타나지 않으면 검색 막대 끝에 div를 추가하고 싶습니다. 그러나 matcher 함수로 인해 내 형광펜이 깨져서 임의의 결과가 반환됩니다. matcher 함수를 사용하지 않고이 작업을 수행 할 방법이 있는지 또는이 인스턴스에서 제대로 사용하는 방법을 알고 있습니까? 나는 내가 잘못된 접근법을 취하고 있다고 생각한다.matcher 함수 typeahead
$('.shop_search').typeahead({
source: function (query, process) {
map = {};
$.each(data, function (i, data) {
map[data.text] = {
address: data.text2,
name: data.text,
post: data.post
};
shops.push(data.text);
});
process(shops);
shops = [];
},
minLength: 3,
matcher: function (item) {
if (item.indexOf(this.query) == -1) {
$(".dropdown-menu").append($('<li><button class="btn" >Advanced Search</button></li>'));
return true;
}
},
highlighter: function (item) {
var p = map[item];
var itm = ''
+ "<div class='typeahead_primary'>" + p.name + "</div>"
+ "<div class='typeahead_secondary'>" + p.address + </div>"
+ "</div>"
+ "</div>";
return itm;
},
});