How to add new child nodes according to the parent node in the element-ui tree table

for example, when I enter the page, I get first-level categories, such as data

.
data : [
    {
        id: "2",
        parentId: 1,
        name : ""
    },
    {
        id: "2",
        parentId: 1,
        name : "2"
    }
]

then query the API to the backend based on this id, such as the query to id=2, and then get the subordinate

.
[
    {
        id: "5",
        parentId: 2,
        name : ""
    },
    {
        id: "6",
        parentId: 2,
        name : "2"
    }
]

how to implement, how to insert the query into the parent class as his children


load the query lazily, which is automatically inserted by the tree control.
https://codeshelper.com/q/10.


if you only realize the fusion of parent and child data manually, it will be fine:

children.forEach(child => {
    let parent = data.find(item => item.id == child.parentId)
    parent && (parent.children || (parent.children = [])) && parent.children.push(child)
})
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-1b30494-2bcf7.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-1b30494-2bcf7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?