小编dro*_*sen的帖子

Typeahead.js 0.10.x:如何显示每个类别的结果数

Typeahead.js 0.10支持页眉和页脚以及搜索结果的模板.我希望能够获得每个类别的实际结果/建议数(即忽略限制值)并在类别名称标题中显示.

例如 -

结果:

  • A类(24结果)
    • -A1
    • -A2
    • -A3
  • B类(167结果)
    • -B1
    • -B2
    • -B3

我的模板目前看起来像这样:

{
name: 'Applications',
displayKey: 'value',
source: app.ttAdapter(),
extraVars:Handlebars.registerHelper("numResults",function(){
    return (  "HowToGetTheseResults??" );
}),
templates: {
    header:Handlebars.compile([
        '<h3 class="applications"> Applications ({{numResults}}) results  </h3>'
    ].join('')),

    suggestion: Handlebars.compile([
        '<p><b>{{value}}</b> </p>'
    ].join(''))
}
Run Code Online (Sandbox Code Playgroud)

是否有一种简单的方法可以提前输入结果/建议的数量?我确定typeahead对象(或者是bloodhound对象?)必须在某个地方存储这些数据.

typeahead.js twitter-typeahead

5
推荐指数
1
解决办法
1849
查看次数

标签 统计

twitter-typeahead ×1

typeahead.js ×1