简体   繁体   English

更改Algolia Instantsearch.js统计信息模板

[英]Change Algolia instantsearch.js stats template

How could I change Change Algolia instantsearch.js stats template? 我怎么能变化而变化Algolia instantsearch.js统计模板? (X results found in Y m/s) (在Y m / s中找到X个结果)

According to documentation it could be done via options.template, but that's it. 根据文档 ,可以通过options.template完成,仅此而已。 Which variables represent results count and time , and perhaps other variables? 哪些变量代表结果计数时间 ,也许还有其他变量?

What is the best way to create a template? 创建模板的最佳方法是什么?

This is what I have so far: 这是我到目前为止的内容:

instantsearch.widgets.stats({
  container: '#stats'
})

Most probably I should add: 我很可能应该添加:

instantsearch.widgets.stats({
  container: '#stats',
  template: '#stats-template'
})

and then the template (what should be the variables?): 然后是模板(变量应该是什么?):

<script type="text/html" id="stats-template">
    <div data-reactroot="" class="ais-root ais-stats">
      <div class="ais-body ais-stats--body">
        <div>
          {{number of hits}} hits found
        </div>
      </div>
    </div>
</script>

Templates in Algolia work a bit differently, here is how your instantsearch.widgets.stats should look like: Algolia模板的工作有点不同,这里是你如何instantsearch.widgets.stats应该是这样的:

instantsearch.widgets.stats({
  container: '#stats', // Your stats container
  templates: {
    body: getTemplate('stats') // Template for displaying stats
  }
})

and the template: 和模板:

<script type="text/html" id="stats-template">
    <div data-reactroot="" class="ais-root ais-stats">
      <div class="ais-body ais-stats--body">
        <div>
          {{nbHits}} products found
        </div>
      </div>
    </div>
</script>

Full list of variables you can use in your stats template: 您可以在统计信息模板中使用的变量的完整列表:

hasManyResults, hasNoResults, hasOneResult, hitsPerPage, nbHits, nbPages, page, processingTimeMS, query

More information: https://community.algolia.com/instantsearch.js/documentation/#stats 更多信息: https : //community.algolia.com/instantsearch.js/documentation/#stats

There is an example here: https://community.algolia.com/instantsearch.js/documentation/#templates 这里有一个例子: https : //community.algolia.com/instantsearch.js/documentation/#templates

search.addWidget(
    instantsearch.widgets.stats({
        container: '#stats',
        templates: {
            body: function(data) {
                return 'Show ' + data.nbHits + ' results'
            }
        }
    })
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM