2

저는 부트 스트랩 v2.3.2를 사용하고 있으며 데이터베이스에서 데이터를 가져 오는 일반적인 터 셔널을 설정했습니다.Typeahead : 마지막 옵션 추가

각 첨단의 마지막 결과가 "< 검색 입력 : >"옵션이되도록 노력하고 있습니다. 입력에 "hello"라고 입력하면 마지막 결과 (다른 모든 결과 아래)는 Search for "hello"이됩니다.

어떻게 처리할까요?

+0

당신의 선입견 코드를 공유 할 수 있습니까? –

답변

1

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 가지를 사용했다. 이것을 구현하려면 형광펜 기능을 수정해야했습니다.

이 정보가 도움이되기를 바랍니다.