Algorithm for Transforming Data Structures in Tree Plugin Displays
Published: 2017-06-03
Problem Background
// Two-dimensional data structure
[{
"id": "001",
"name": "Headquarters",
"parentId": "0"
}, {
"id": "002",
"name": "Secondary Store 1",
"parentId": "001"
}, {
"id": "003",
"name": "Tertiary Store",
"parentId": "002"
}, {
"id": "004",
"name": "Secondary Store 2",
"parentId": "001"
}]
// Tree data structure
[{
"id": "001",
"name": "Headquarters",
"parentId": "0",
"children": [{
"id": "002",
"name": "Secondary Store 1",
"parentId": "001",
"children": [{
"id": "003",
"name": "Tertiary Store",
"parentId": "002",
"children": []
}]
}, {
"id": "004",
"name": "Secondary Store 2",
"parentId": "001",
"children": []
}]
}]
Solution
Two-dimensional structure => Tree structure
Tree structure => Two-dimensional structure
PreviousDeep Dive into JavaScript's Asynchronous Mechanism from setTimeoutNextLooking at LeTV from the National Financial Work Conference
Last updated