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

将原始问题中的代码更改为我粘贴到上述答案中的代码 –