我正在尝试在我的应用程序中实现一个使用redux-search的react / redux的搜索过滤器。我得到的第一个问题是当我尝试添加商店增强器时,如示例中所示。
// Compose :reduxSearch with other store enhancers
const enhancer = compose(
applyMiddleware(...yourMiddleware),
reduxSearch({
// Configure redux-search by telling it which resources to index for searching
resourceIndexes: {
// In this example Books will be searchable by :title and :author
books: ['author', 'title']
},
// This selector is responsible for returning each collection of searchable resources
resourceSelector: (resourceName, state) => {
// In our example, all resources are stored in the state under a :resources Map
// For example "books" are stored under state.resources.books
return state.resources.get(resourceName)
}
})
)

我理解evadthing到resourceSelector,当我试图深入了解它的例子以了解它是如何工作但我几乎看不到它们是如何生成的并且最后一行返回错误,无法读取属性'让'未定义的
我的状态对象看起来像这样
state: {
//books is an array of objects...each object represents a book
books:[
//a book has these properties
{name, id, author, datePublished}
]
}

任何了解redux-search的人都可以提供帮助
答案 0 :(得分:1)
如果这一行:
return state.resources.get(resourceName)
导致此错误:
无法阅读财产' get'未定义的
这表明state.resources
未定义。当然,您的州没有定义resources
属性。
这些示例的编写考虑了使用redux-search
索引许多类型的资源,例如:
state: {
resources: {
books: [...],
authors: [...],
// etc
}
}
您报告的问题的解决方案是:
resources
对象(如果您认为将来可能想要将其他内容编入索引并且您喜欢该组织)。state.resources.get(resourceName)
替换为state[resourceName]
或类似。