我试图用孩子计算一组对象的重量总和,但是我认为我做错了。我正在尝试使用可搜索的下拉包来显示包裹列表。个人应该能够选择包裹类别并在文本标签中查看所选包裹的总重量。下面是我的代码包裹类别.js export const ParcelCategories = [ { name: "Men's", id: 0, children: [ { name: 'Clothing', id: 10, Weight: 4, }, { name: 'Shirts', id: 11, Weight: 3, }, { name: 'Jackets & Coats', id: 13, Weight: 2, }, { name: 'Hoodie & Sweatshirts', id: 14, Weight: 4, }, { name: 'Shorts', id: 15, Weight: 4, }, { name: 'Jeans', id: 17, Weight: 2, }, { name: 'Sneakers', id: 18, Weight: 1, }, { name: 'Loafers & Slip-ons', id: 19, Weight: 4, }, ] } ];
2 回答
阿晨1998
TA贡献2037条经验 获得超6个赞
首先,您需要修复导入语句:
// needs braces if you aren't exporting default
import { ParcelCategories } from './parcelCategories'
在你的SectionedMultiSelect道具中:
<SectionedMuliSelect
items={ParcelCategories}
// ...the rest of the code
如果您使用ParcelCategories中的项目SectionedMultiSelect,您应该能够执行以下操作:
addValues = () => {
const { selectedItemObjects } = this.state
const total = selectedItemObjects.reduce((result, { Weight }) => result += Weight, 0)
return total
}
添加回答
举报
0/150
提交
取消