Home  >  Forum  >  Spring
Post New Query

How to retrieve json data in tree format



Asked on January 17, 2018
Hello,

I want to retrieve data from data base in tree format like for example
this.nodes = [
{
expanded: true,
name: 'root expanded',
subTitle: 'the root',
children: [
{
name: 'child1',
subTitle: 'a good child',
hasChildren: false
}, {
name: 'child2',
subTitle: 'a bad child',
hasChildren: false
}
]
},
{
name: 'root2',
subTitle: 'the second root',
children: [
{
name: 'child2.1',
subTitle: 'new and improved',
hasChildren: false
}, {
name: 'child2.2',
subTitle: 'new and improved2',
children: [
{
uuid: 1001,
name: 'subsub',
subTitle: 'subsub',
hasChildren: false
}
]
}
]
},
{
name: 'asyncroot',
hasChildren: true
}
];

but my database returns data in the below format
[{"pk_location_id":1,"tenant_id":null,"locationname":"India","locationpath":null,"location_phone":"9972317626","location_fax":null,"locationcode":"loc01","location_user_license_code":null,"location_license":null,"location_description":null,"location_area":null,"location_district":null,"location_street_address_1":null,"location_street_address_2":null,"location_city":null,"location_state":null,"location_postal_code":null,"location_country":"India","location_roles_id":null,"parent_location_id":0,"created_date":null,"modified_date":null,"deleted":0,"has_children":true},{"pk_location_id":2,"tenant_id":null,"locationname":"Karnataka","locationpath":"/[India]","location_phone":"9448124312","location_fax":null,"locationcode":"loc02","location_user_license_code":null,"location_license":null,"location_description":null,"location_area":null,"location_district":null,"location_street_address_1":null,"location_street_address_2":null,"location_city":null,"location_state":null,"location_postal_code":null,"location_country":"India","location_roles_id":null,"parent_location_id":1,"created_date":null,"modified_date":null,"deleted":0,"has_children":false}]

kindly anyone help me out in this.

Thanks



Write Answer








©2019 concretepage.com | Privacy Policy | Contact Us