我正在用json创建对象数组,但没有(正确的)顺序。顺序取决于不同的键,也取决于应为其创建顺序的“级别” /键。有什么方法可以创建这样的订单吗?
数组是多个Angular Material Tables的数据源,其中对象应显示在不同的表中(因此我还必须创建一个数组数组)
数据本身看起来像:
power: [5,10,15]
pwoer2: [0,10,15]
power3: [1000,2000,3000]
我在json中的数组看起来像这样,甚至还有更多键:
"test_comp": [
{
"power": 5,
"power2": 0,
"power3": 1000
},
{
"power": 10,
"power2": 0,
"power3": 1000
},
{
"power": 15,
"power2": 0,
"power3": 1000
},
{
"power": 5,
"power2": 10,
"power3": 1000
},
{
"power": 10,
"power2": 10,
"power3": 1000
},
{
"power": 15,
"power2": 10,
"power3": 1000
},
...
{
"power": 15,
"power2": 15,
"power3": 3000
}
]
但是我想要的是:
{
"power": 5,
"power2": 0,
"power3": 1000
},
{
"power": 5,
"power2": 0,
"power3": 2000
},
{
"power": 5,
"power2": 0,
"power3": 3000
},
{
"power": 5,
"power2": 10,
"power3": 1000
},
{
"power": 5,
"power2": 10,
"power3": 2000
},
{
"power": 5,
"power2": 10,
"power3": 3000
},
{
"power": 5,
"power2": 15,
"power3": 1000
},
...
{
"power": 15,
"power2": 15,
"power3": 3000
}
]
最后,我希望此数组将其保存为对象数组,但这在对主数组进行排序之后很容易