Jbb*_*bae 3 javascript reactjs algolia react-instantsearch
所以我已经在我的应用程序中成功实现了React InstantSearch库,并尝试将过滤器应用于细化列表(以确保显示的过滤器与活动用户相关,并隐藏不存在的过滤器).我试过以下:
<RefinementList attributeName="organization" transformItems={items => items.filter(e => refineList.indexOf(e)>=0)} />
Run Code Online (Sandbox Code Playgroud)
其中refineList是一个简单的字符串数组(即["A","B","C"])
但是,RefinementList会一直显示所有过滤器选项,而不会应用"transformItems"函数.是不是我误解了"transformItems"是如何工作的?
关于这个主题的文档很少,所以我相信它对图书馆的许多其他用户都有帮助.
小智 7
该transformItems函数有一个参数:items.它期望回归它.
items 是具有以下形状的对象数组:
{
label: string,
value: array<string>,
count: number,
isRefined: bool,
}
Run Code Online (Sandbox Code Playgroud)
要根据字符串数组删除细化,可以执行以下操作:
const refineList = ['A', 'B'];
<RefinementList
attributeName="organization"
transformItems={items => items.filter(e =>
refineList.indexOf(e.label) >= 0)}
/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
414 次 |
| 最近记录: |