Algolia initial search parameters instantsearch.js

萝らか妹 提交于 2019-12-05 10:24:54

I assume you are using a refinementList widget: https://community.algolia.com/instantsearch.js/documentation/#refinementlist. On the 'category' attribute of your data.

If so, you can do this:

var preselectedCategories = ['Careers', 'Skills'];

var search = instantsearch(applicationID, apiKey, {
  ...other parameters,
  searchParameters: {
    disjunctiveFacetsRefinements: {
      category: preselectedCategories
    }
  }
})

You will also need to do this in the refinementList instantiation:

var refinementList = instantsearch.widgets.refinementList({
  transformData: {
    item: function(item) {
      if (preselectedCategories.indexOf(item.name) !== -1) {
        item.cssClasses.label += ' pre-selected';
      }

      return item;
    }
  }
});

Then all the preselected categories items will have the "pre-selected" css class by default.

Then you can use css and this class name to do:

.pre-selected {
  display: none;
}

Let me know

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!