用于通过嵌套数组ngrx循环的选择器
为了访问此JSON的项目数组,我应该如何使用选择器?
const list = {
"nestedService": [
{
"categories": [
{
"name": "test1",
"items": [
{
"itemCat": [
{
"code": "123"
}
]
}
]
},
{
"name": "test2",
"items": [
{
"itemCat": [
{
"code": "345"
}
]
}
]
}
]
}
]
}
以下是我尝试获得列表的嵌套服务,我需要帮助获取项目
export const getItems =
createSelector(selectState,(state) => {
const data = state.list
return data?.map(e => e.nestedService);
});
In order to access the items array from this JSON, how should I use a selector?
const list = {
"nestedService": [
{
"categories": [
{
"name": "test1",
"items": [
{
"itemCat": [
{
"code": "123"
}
]
}
]
},
{
"name": "test2",
"items": [
{
"itemCat": [
{
"code": "345"
}
]
}
]
}
]
}
]
}
The following is what I tried to get nestedServices for the list, I needed help in fetching items
export const getItems =
createSelector(selectState,(state) => {
const data = state.list
return data?.map(e => e.nestedService);
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
List
是一个对象,因此使用MAP
是一个错误。使用选择器
以获取从商店确切需要的东西是正确的选择。只需返回您想要的确切属性:
list
is an object, so usingmap
is a mistake. Using aselector
for grabbing what you exactly need from the store is the right choice.Just return the exact property you want: