jQuery UI Widgets › Forums › General Discussions › Navigation › Tree › Problem retrieving item collection
Tagged: child, Collection, item, jqxtree, json, parent, parentId, source, Sub Items, Tree, Tree View
This topic contains 2 replies, has 2 voices, and was last updated by iao93 11 years, 9 months ago.
-
Author
-
Hi,
Am having an issue with retrieving the child nodes of my tree-view. I’m thinking there might be something wrong with the JSON string format that I’m returning from the server.
Code:
var source = { datatype: "json", async: false, datafields: [ { name: 'id' }, { name: 'parentid' }, { name: 'label' } ], items: [ { name: 'id' }, { name: 'parentid' }, { name: 'label' } ], id: 'id', url: 'Charts.aspx?callback=GetTreeData' }; var dataAdapter = new $.jqx.dataAdapter(source); dataAdapter.dataBind(); var records = dataAdapter.getRecordsHierarchy("id", "parentid", "items"); $('#jqxWidget').jqxTree({ source: records, width: '300px' });This is the JSON string I’m receiving from the server:
[{“id”:”178″,”parentid”:”-1″,”label”:”Parent Item 1″,”value”:null,”icon”:null,”items”:[{“id”:”78″,”parentid”:”178″,”label”:”Child Item 1″,”value”:null,”icon”:null,”items”:null},{“id”:”79″,”parentid”:”178″,”label”:”Child Item 2″,”value”:null,”icon”:null,”items”:null} …… and so on…
My tree view is only displaying the root nodes but not any child nodes.
Kindly advise me on what I’m doing wrong.
Thank you in Advance,
AJHello AJ,
In the demo JSON Tree you can see what your JSON source should look like to successfully create a tree. The main difference from your approach is not having “items” but only a reference to the parent: “parentid”.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Thank you Dimitar,
Got it working now!
Warmest,
AJ -
AuthorPosts
You must be logged in to reply to this topic.