Recursively process the data from the back end and process it into an vue routing format that can be used

Thank you all for your answers. The problem has been solved. Thank you
var rr = [

].
    {"pid":0,"id":3,"name":"3"},
    {"pid":0,"id":4,"name":"4"},
    {"pid":4,"id":5,"name":"-4"},
    {"pid":5,"id":6,"name":"-4-1"},
    {"pid":0,"id":7,"name":"7"},
    {"pid":7,"id":8,"name":"-7"},
    {"pid":0,"id":9,"name":"9"},
    {"pid":9,"id":10,"name":"9-1"},
    {"pid":9,"id":11,"name":"9-2"},
    {"pid":11,"id":12,"name":"9-2-1"}

];

ask God to help you recursively process the data in the above format into a format that can be used by vue routing. In the above data, a pid of 0 represents a first-level route, and a pid equals an id with a pid of 0 represents a second-level route. And so on.

May.14,2021

    var map = {};
    rr.forEach(function (item) {
        map[item.id] = item;
    });
    var newData = [];
    rr.forEach(function (item) {
        var parent = map[item.pid]; // pid,mapid
        if (parent) {
            // ,
            (parent.children || (parent.children = [])).push(item);
        } else {
            //mapID,itemnewData
            newData.push(item);
        }
    });

suddenly remembered something I had done before

clipboard.png

clipboard.png

clipboard.png


clipboard.png


20189710:01:30


clipboard.png


child:[]children:[]




clipboard.png


suggest payment withdrawal

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eaebaa-21fc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eaebaa-21fc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?