【发布时间】:2018-10-09 02:26:36
【问题描述】:
我想为两个不同的索引使用两个不同的项目模板自定义我的 algolia 搜索结果,但我不知道该怎么做。我在文档中也找不到这方面的内容。
在这里你可以看到我现在是如何做到的。
<script type="text/html" id="hit-template">
<div class="hit">
<div class="head">
<span class="title">@{{{_highlightResult.title.value}}}</span>
<span class="tag">@{{{_highlightResult.category.value}}}</span>
</div>
<div class="details">
<span>@{{{ article_votes }}} @{{{ comment_votes }}} Points</span> ·
<span>@{{{ username }}}</span> ·
<span>@{{{ created_at }}}</span>
<span class="domain">@{{{_highlightResult.link.value}}}</span>
</div>
<p class="comment-text">@{{{_highlightResult.body.value}}}
@{{{_highlightResult.description.value}}}</p>
</div>
</script>
search.addWidget(
instantsearch.widgets.hits({
container: '#hits-container',
templates: {
empty: 'Sorry, there are no results.',
// Here I need two item templates one for comments and one for articles
item: document.getElementById('hit-template').innerHTML
},
escapeHits: true,
transformItems: items => items.map(item => item),
})
);
【问题讨论】: