从MySQL / JSON数据创建JSON分层树

时间:2019-03-14 19:13:54

标签: javascript json ecmascript-6

我有一个非常大的JSON对象,我需要进入一棵树,但是我不确定该怎么做。我正在将VueJs与内置了Treeview的Vuetify一起使用,但我不知道如何为树准备好数据。

这是我的数据... https://tpcrm.totalprocessing.com/api/get-channels

我需要的是(显然没有包括所有数据)

items: [
    {
        name: "Adboom",
        id: "8ac9a4cb64b143910164b1b2ab0305db"
        children: [
            {
                name: "Jaydox LTD",
                id: "8ac9a4cb64b143910164b1b3009b05e2"
                children: [
                    {
                        name: "beautifullyyoungskin.net"
                        id: "8ac9a4cb64b143910164b1b8004b063a"
                    },
                    {
                        name: "thinbodydiet.com"
                        id: "8ac9a4cb64b143910164b1b74af10630"
                    },
                    {
                        name: "youthfulskincare.net"
                        id: "8ac9a4cb64b143910164b1b77ba70634"
                    }
                ]
            }
        ]
    },
    {
        name: "Adult",
        id: "8ac9a4c96489324601649354068034ab"
        children: [
            {
                name: "Occonti Ltd",
                id: "8ac9a4c965a8666d0165af279ca228dd"
                children: [
                    {
                        name: "datinginthe.eu (3d Secure)"
                        id: "8ac9a4cd65a866700165b47a25c74e61"
                    },
                    {
                        name: "datinginthe.eu (Non-3d)"
                        id: "8ac9a4cd65a866700165b478f0574e48"
                    },
                    {
                        name: "datinginthe.eu - ST (Non-3d)"
                        id: "8ac9a4ca65a8a0670165d34366d53fc9"
                    },
                    {
                        name: "datinginthe.eu ST (3d Secure)"
                        id: "8ac9a4cb66aafd790166ad040a170b68"
                    }
                ]
            }
        ]
    }
]

1 个答案:

答案 0 :(得分:1)

通过对find … |mapfile …printf使用相同的模式,您可以使用一组关键部分并查找其ID和分组。

name
id