【发布时间】:2019-10-14 19:44:07
【问题描述】:
我有一个 ibject 数组,每个元素内部都有另一个对象,例如
data = [
{
name: "A",
type: "AA",
children: [ { id: 1, name: "Child-A", admin: ["Y"] }],
other: "NA"
},
{
name: "B",
type: "BB",
children: [ { id: 2, name: "Child-B" }],
other: "NA"
},
{
name: "C",
type: "CC",
children: [ { id: 3, name: "Child-C" }],
other: "NA"
}
]
我想通过children.id 值对整个集合进行排序,但要基于另一个数组给出的顺序
orderArray = [3, 1, 2]
所以输出将是
data =[
{
name: "C",
type: "CC",
children: [ { id: 3, name: "Child-C" }],
other: "NA"
},
{
name: "A",
type: "AA",
children: [ { id: 1, name: "Child-A", admin: ["Y"] }],
other: "NA"
},
{
name: "B",
type: "BB",
children: [ { id: 2, name: "Child-B" }],
other: "NA"
}
]
【问题讨论】:
标签: javascript angular typescript sorting