【发布时间】:2023-01-26 19:12:11
【问题描述】:
我看到很多类似的问题。但他们都没有帮助我满足我的需要。所以我发布了这个问题。
根据用户的选择,我有多个阵列。作为示例,我将在这里使用 2 个数组。
color = [{id: 1, name: "Red"}, {id: 2, name: "Green"}, {id: 1, name: "Blue"}]
size = [{id: 1, name: "Small"}, {id: 2, name: "Medium"}]
我想获得给定数组的所有可能组合,并在其上添加一些键作为输出。
我的预期输出如下所示。
[{"color": "Red", "size": "Small", "price":0, "Quantity": 0},
{"color": "Red", "size": "Medium", "price":0, "Quantity": 0},
{"color": "Green", "size": "Small", "price":0, "Quantity": 0},
{"color": "Green", "size": "Medium", "price":0, "Quantity": 0},
{"color": "Blue", "size": "Small", "price":0, "Quantity": 0},
{"color": "Blue", "size": "Medium", "price":0, "Quantity": 0}]
如果用户提供 3 个数组,那么它应该相应地创建组合,但是属性 "price" 和 "Quantity" 将被添加到组合中。
请向我建议如何在 Angular 中实现这一点?
【问题讨论】:
-
price和quantity来自哪里? -
如果用户给出 3 个数组,但您只向我们展示了 2 个数组。第三阵是?
标签: javascript arrays angular combinations