0

我在導航欄中使用Twitter typeahead.js v0.11.1調用WebApi並根據搜索框的輸入返回結果,它工作正常的搜索框。Twitter typeahead.js被忽略的模板設置

但是,當我嘗試添加模板設置時,它們將被忽略,並且單個名稱jsonProperty仍然是下拉菜單中返回的唯一內容。

我已經設置了預輸入如下

var matchList = new Bloodhound({ 
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('SmartSearchDto'), 
    queryTokenizer: Bloodhound.tokenizers.whitespace, 
    limit: 10, 
    remote: { 
     url: 'http://myserver/api/smartsearch/search?searchTerm=%QUERY', 
     wildcard: '%QUERY' 
    } 
}); 
matchList.initialize(); 
$('.typeahead').typeahead({ 
    hint: true, 
    highlight: true, 
    minLength: 1, 
    templates: { 
      suggestion: function(data) { 
      return '<p><strong>' + data.name + '</strong> - ' + data.entitytype + '</p>'; 
      } 
     } 
    }, 
    { 
     displayKey: 'name', 
     name: 'SmartSearchDto', 
     source: matchList.ttAdapter() 
    } 
); 

有什麼明顯的,我做錯了什麼?發佈後

回答

0

1分鐘我的工作了:

var matchList = new Bloodhound({ 
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('SmartSearchDto'), 
    queryTokenizer: Bloodhound.tokenizers.whitespace, 
    limit: 10, 
    remote: { 
     url: 'http://localhost:59019/api/smartsearch/search?searchTerm=%QUERY', 
     wildcard: '%QUERY' 
    } 
}); 
matchList.initialize(); 
$('.typeahead').typeahead({ 
    hint: true, 
    highlight: true, 
    minLength: 1 
    }, 
    { 
     templates: { 
      suggestion: function(data) { 
       return '<p><strong>' + data.name + '</strong> - ' + data.entitytype + '</p>'; 
      } 
     }, 
     source: matchList.ttAdapter() 
    } 
); 
+0

什麼是分辨率?這裏也有問題。 –

+0

將原始問題中的代碼更改爲我粘貼到上述答案中的代碼 –