extjs - How to populate a Tree with flat JSON? -
i receiving json response api following objects structure:
{ "servers": [ { "name": "root company ltd.", "guid": "{1760f250-5012-46b2-8bbf-955ffd1c51ad}", "parentguid": null, "active": true, "connected": true }, { "name": "25-tecvoz hlv1wad", "guid": "{cc893441-a3b5-42b2-95b6-f3e56f0286ae}", "parentguid": "{1760f250-5012-46b2-8bbf-955ffd1c51ad}", "active": true, "connected": true }, { "name": "20-axis m1031", "guid": "{216142b2-a9b8-4aff-85cd-1d97685f4ee1}", "parentguid": "{1760f250-5012-46b2-8bbf-955ffd1c51ad}", "active": true, "connected": true }, // ... ] }
as can see, json structure "flat", object's children not nested parents, when building tree panel, objects parentguid
set should nested object matching guid
.
the tree doesn't need dynamic, mean doesn't need make new request server every time open node, json complete set of information server already.
i using following model:
ext.define('web.model.server', { extend : 'ext.data.model', requires: [ 'web.globals' ], idproperty: 'guid', // "fields" , "validators" skipped... proxy: { type: 'rest', url: web.globals.getaddress('/api/servers'), appendid: false, reader: { type: 'json', rootproperty: 'servers' } } });
the store:
ext.define('web.store.servers', { /* url /api/servers */ extend: 'ext.data.treestore', alias: 'store.servers', model: 'web.model.server', root: {expanded: true} });
and panel:
{ xtype : 'treepanel', name : 'servers', title : 'select server', flex : 1, overflowy : 'scroll', autoscroll : true, margin : 5, store : ext.create('web.store.servers'), rootvisible : false, displayfield: 'name', autoload: true, }
how can accomplish this? wasn't able find clear way in documentation.
Comments
Post a Comment