我有一个表格模式数组对象,如下所示,直到 n 级。它可以是任何父母孩子的记录
var records = [
{ country: "USA", state: "FLORIDA", city: "city1" },
{ country: "USA", state: "FLORIDA", city: "city2" },
{ country: "USA", state: "FLORIDA", city:"city3" },
{ country: "USA", state: "ALASKA" },
{ country: "USA", state: "ALBAMA" },
]
var columns = ["country","state","city"] // upto n column
我需要按以下格式对第 n 级进行分组,因为可以有 n 级关系,按以下格式对记录进行分组
{
sequencer: 1, value: 'USA', loop: [
{ sequencer: 1, value: 'FLORIDA', loop: [
{ sequencer: 1, value: 'city1' },
{ sequencer: 2, value: 'city2' },
{ sequencer: 3, value: 'city3' },
], },
{ sequencer: 2, value: 'ALASKA' },
{ sequencer: 3, value: 'ALBAMA' },
],
}
有人可以编写一个递归函数来对 n 级列对象进行分组。谢谢
翻过高山走不出你
慕标琳琳
相关分类