Customize
Do something on the node
New Node From List
You can change the "new_node" method to do something with the node when creating a tree from a list.
In this example, if the node id is "2", a new key will be added to the node.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
Output:
[
{
"id": 1,
"parent": 0,
"flow": "1",
"children": [
{
"id": 2,
"parent": 1,
"new_key": "new value",
"flow": "1-1",
"children": [
{
"id": 4,
"parent": 2,
"flow": "1-1-1"
}
]
},
{
"id": 3,
"parent": 1,
"flow": "1-2"
}
]
},
{
"id": 5,
"parent": 0,
"flow": "2"
}
]
New Node From Tree
You can change the "new_node_list" method to do something with the node when creating a list from a tree.
In this example, if the node id is "3", a new key will be added to the node.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
Output:
[
{
"id": 1,
"parent": 0
},
{
"id": 2,
"parent": 1
},
{
"id": 3,
"parent": 1,
"new_key": "new value"
},
{
"id": 4,
"parent": 0
}
]
Changing the flow key
To change the logic of the sequence you can change the methods "make_parent_flow" and "make_child_flow".
Let's see the original implementation:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Now you can change it according to your need.
In this example, the parent node will start with the value "0" and we change the string format by replacing the character "-" with "_"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
Output:
[
{
"id": 1,
"parent": 0,
"flow": "0",
"children": [
{
"id": 2,
"parent": 1,
"flow": "0_0",
"children": [
{
"id": 4,
"parent": 2,
"flow": "0_0_0"
}
]
},
{
"id": 3,
"parent": 1,
"flow": "0_1"
}
]
},
{
"id": 5,
"parent": 0,
"flow": "1"
}
]