02-21-2019 7:35 PM
Hi Folks,
when i get JSON data like this.
// JSON sample data
var data = {
company:{
name:"Treefish Inc",
info:{
employees:3,},
contacts:[{
name:"Barbara",
phone:"873"},{
name:"Gerry",
phone:"734"},{
name:"Susan",
phone:"275"}]}};
Absolute binding paths within this model when i know the structure of the data.
/company/name
/company/info/employees
/company/contacts
How can i get the sub paths when i have only the path /company.
Is there an function to get this?
Thanks for any help
Bernd
02-22-2019 6:52 AM
you need to do it manually.
var data = {
company:{
name:"Treefish Inc",
info:{
employees:3,},
contacts:[{
name:"Barbara",
phone:"873"},{
name:"Gerry",
phone:"734"},{
name:"Susan",
phone:"275"}]}};
// This will give you the properties inside the object
var keys = Object.keys(data );
// ["company"]
var keys = Object.keys(data.company );
// ["name", "info", "contacts"]
// So you have to call it recursivvely to fetch all the paths...
// You can also use
for(var sProperty in data){
//data[sProperty]
}
So you need to wirte a function to do it recursively and give you the paths.. Is there any reason to do that dynamically?
BR,
Mahesh
02-22-2019 6:52 AM
you need to do it manually.
var data = {
company:{
name:"Treefish Inc",
info:{
employees:3,},
contacts:[{
name:"Barbara",
phone:"873"},{
name:"Gerry",
phone:"734"},{
name:"Susan",
phone:"275"}]}};
// This will give you the properties inside the object
var keys = Object.keys(data );
// ["company"]
var keys = Object.keys(data.company );
// ["name", "info", "contacts"]
// So you have to call it recursivvely to fetch all the paths...
// You can also use
for(var sProperty in data){
//data[sProperty]
}
So you need to wirte a function to do it recursively and give you the paths.. Is there any reason to do that dynamically?
BR,
Mahesh
02-22-2019 11:01 PM
02-22-2019 11:25 PM
You can mark the answer as answered and close the question if your query is solved.
https://blogs.sap.com/2013/04/03/how-to-close-a-discussion-and-why/
BR,
Mahesh
02-26-2019 7:25 PM
I have a dynamically struktur so I do this dynamically.
Does exist an other solution?