问题如下。我们使用algolia即时搜索。每种产品都有卖家。当前用户订阅了一些卖家。用户应该可以通过订阅的卖家和没有的卖家来过滤产品。为此,我尝试使用窗口小部件切换。其中,我为当前用户设置了用逗号分隔开和关选项的订阅卖家列表
values: {
on: '37,41,67',
off: '45,56',
},但它只有在我只指定一个卖家的情况下才起作用。并满足默认选项为off。我尝试过使用numericRefinementList小部件
options: [
{ label: 'On', value: '37,41,67' },
{ label: 'Off', value: '45,56' },
],但是它也不能工作,有人能提出一个解决方案吗?
发布于 2017-05-16 17:08:22
这不是默认窗口小部件所涵盖的行为。但是,您可以制作自定义小部件来打开筛选器列表。让我给你举个例子:
const sellerList = [];
// this uses jQuery
const toggleButton = $('div.toggleSellers');
const search = instantsearch(/* parameters and credentials */);
search.addWidget({
getConfiguration: function() {
return {disjunctiveFacets: ['seller']};
},
init: function(options) {
const helper = options.helper;
// Here you have to bind the event that will toggle seller
// For example using the `toggleButton` and a click event
toggleButton.on('click', function() {
sellerList.forEach(function(seller) {
helper.toggleRefinement('seller', seller);
});
});
},
});"seller"是记录中包含卖方的属性的名称。它应该被配置为您的Algolia仪表板中的一个方面。
sellerList是在索引的"seller"属性中使用的卖方标识符的列表。
此自定义小部件使用jsHelper,它允许您指定搜索的参数。此外,您还可以在文档中找到有关the custom widgets的更多信息。
https://stackoverflow.com/questions/43957378
复制相似问题