小编A.Q*_*Qua的帖子

javascript中的父子关系排序

我有以下结构

[
    {
         "category_id" : 1,
         "parent_category" : null
    } ,
    {
         "category_id" : 2,
         "parent_category" : 1
    },
    {
         "category_id" : 3,
         "parent_category" : 1
    },
    {
         "category_id" : 4,
         "parent_category" : 2
    },
    ,
    {
         "category_id" : 5,
         "parent_category" : null
    },
    ,
    {
         "category_id" : 6,
         "parent_category" : 5
    }


]
Run Code Online (Sandbox Code Playgroud)

所以我有父子关系,我想用以下结构对其进行排序

[
    {
      "parent_category":[ "array of all children that follow this main parent category" ]  
    },
    {},
    {}
]
Run Code Online (Sandbox Code Playgroud)

我见过很多解决方案,但都是关于树结构输出的

谢谢

javascript sorting tree

5
推荐指数
1
解决办法
971
查看次数

标签 统计

javascript ×1

sorting ×1

tree ×1