【发布时间】:2022-01-30 10:24:06
【问题描述】:
我有一个如下所示的数组对象:
[{
sellerId: "seller1",
name: "Nike",
item: [{
id: "xxx1"
isChecked: false
price: "719700.00"
productName: "product a"
quantity: 2
},
{
id: "xxx2"
isChecked: true
price: "219700.00"
productName: "product b"
quantity: 1
}
],
},
{
sellerId: "seller2",
name: "Adidas",
item: [{
id: "xxx1"
isChecked: false
price: "49700.00"
productName: "product x"
quantity: 1
},
{
id: "xxx2"
isChecked: true
price: "4700.00"
productName: "product y"
quantity: 5
}
],
},
]
现在我想通过 isChecked = true 在名为 Item 的对象上转换或过滤我的数据,所以它看起来像这样:
[{
sellerId: "seller1",
name: "Nike",
item: [
{
id: "xxx2"
isChecked: true
price: "219700.00"
productName: "product b"
quantity: 1
}
],
},
{
sellerId: "seller2",
name: "Adidas",
item: [
{
id: "xxx2"
isChecked: true
price: "4700.00"
productName: "product y"
quantity: 5
}
],
},
]
已编辑:
然后如果没有 isChecked: true 在一个卖家中,它不会显示卖家数据,例如如果阿迪达斯卖家没有 isChecked,我预计对象将如下所示:
[{
sellerId: "seller1",
name: "Nike",
item: [
{
id: "xxx2"
isChecked: true
price: "219700.00"
productName: "product b"
quantity: 1
}
],
},
]
我已经尝试过像这样使用 lodash,但它仍然没有删除具有 isChecked: false 的项目
_.filter(data, { item: [{ isChecked: false }] })
对我如何使用 lodash 或简单的 javascript filter() 有任何帮助吗?
谢谢!
【问题讨论】:
标签: javascript reactjs react-native filter lodash