我有两个数组:
applesToday=
[ {product: "apple", period: 1433113200000, qty: -5},
{product: "apple", period: 1435705200000, qty: -6 },
{product: "apple", period: 1438383600000, qty: -8}
]
applesYesterday =
[ {product: "apple", period: 1433113200000, qty: 10},
{product: "apple", period: 1435705200000, qty: 12 },
{product: "apple", period: 1438383600000, qty: 16}
]
如何将期间字段中的它们合并到:
self.applesTodayYesterday=
[ {product: "apple", period: 1433113200000, qty: -5, qty1: 10},
{product: "apple", period: 1435705200000, qty: -6, qty1: 12 },
{product: "apple", period: 1438383600000, qty: -8, qty1: 16}
]
我尝试使用谷歌搜索左连接,加入键但找不到任何东西......是否有一个很好的库可以做到这一点?
期间将始终是某个月的第一天,并且是每个数组的唯一键
编辑:
目的
我正在使用knockout JS来吐出当前库存表,并希望预先格式化数据,以便每行都是数组中的对象。预先格式化的数据将仅由淘汰赛用于打印到DOM中。
期间是指从树上摘苹果时
[product| period | quantity | daily change | weekly change ] [field 1 | field 2 ]
[apple | apr-15 | 10 | -1 | -12 ] [8% | 20% ]
[apple | may-15 | 12 | -3 | +14 ] [1% | 11% ]
[TOTAL APPLES | 22 | -4 | +2 ] [4% | 43% ]
[carrot | apr-15 | 14 | -7 | -12 ] [8% | 20% ]
[carrot | may-15 | 12 | +1 | +14 ] [1% | 11% ]
[TOTAL CARROTS | 26 | -6 | +2 ] [4% | 43% ]