- edited description
bind treeview with json data
I think this is the best treeview library so far i found.
can you please add an example how to bind treeview with json data
Comments (4)
-
reporter -
Hi Kumar. Thanks for the praise. I am in the process of updating the documentation more and that will include importing from JSON data. Currently, it isn’t a straight forward bind but more of a convenient means to converting JSON into the Node objects needed to use in the TreeView widget. I am working on making this process much simpler.
In the meantime, the way to perform this would be to convert a JSON string into a List. More specifically, a
List<Map<String, dynamic>>
. Then use something like the following to convert that into theList<Node>
needed for the TreeView.List<Node> treeData = jsonList.map((Map<String, dynamic> item) => Node.fromMap(item)); TreeViewController(children: treeData);
The JSON data should look something like this:
[ { "key": "n1", "label": "Parent Node 1", "children": [ {"key": "n1c1", "label": "Item 1"}, {"key": "n1c2", "label": "Item 2"}, {"key": "n1c3", "label": "Item 3"} ] }, {"key": "n2", "label": "Item 4"}, {"key": "n3", "label": "Item 5"} ]
-
reporter Thank you for the reply . i will try this .
-
- changed status to resolved
- Log in to comment