Twitter typeahead.js 模板设置被忽略

Twitter typeahead.js templates settings being ignored

我在导航栏中有一个搜索框,它使用 Twitter typeahead.js v0.11.1 调用 WebApi,return 结果基于搜索框的输入,工作正常。

但是,当我尝试添加模板设置时,它们会被忽略,并且单一名称 jsonProperty 仍然是下拉列表中唯一 returned 的内容。

我已经设置了如下预输入

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()
    }
);

有什么明显的地方我做错了吗?

发帖后 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()
    }
);