json - Search for related properties in the same object. Javascript -


i need matching childrens in same object based on parent id property....

json:

{ "1": { "id": 1, "name": "my crib", "type": "home", "order": 0, "parent": null }, "2": { "id": 2, "name": "first floor", "type": "floor", "order": 1, "parent": { "id": 1, "url": "http://localhost:8080/rest/areas/1" } }, "3": { "id": 3, "name": "garage", "type": "garage", "order": 2, "parent": { "id": 1, "url": "http://localhost:8080/rest/areas/1" } }, "4": { "id": 4, "name": "garden", "type": "garden", "order": 3, "parent": { "id": 1, "url": "http://localhost:8080/rest/areas/1" } }, "5": { "id": 5, "name": "entrance hall", "type": "entrance", "order": 1, "parent": { "id": 2, "url": "http://localhost:8080/rest/areas/2" } }, "6": { "id": 6, "name": "kitchen", "type": "kitchen", "order": 2, "parent": { "id": 2, "url": "http://localhost:8080/rest/areas/2" } }, "7": { "id": 7, "name": "living room", "type": "livingroom", "order": 3, "parent": { "id": 2, "url": "http://localhost:8080/rest/areas/2" } }, "8": { "id": 8, "name": "dog house", "type": "doghouse", "order": 1, "parent": { "id": 4, "url": "http://localhost:8080/rest/areas/4" } } }  const mappedareas = object.keys(areas).map(function(key) {   const area = areas[key];   const wrappers = statics["test.area.groups"]["wrappers"];   const leafs = statics["test.area.groups"]["leafs"];    if (wrappers.indexof(area["type"]) > -1) {       //in array!        //if not home       if(area["type"] != "home"){         console.log("floor:")         console.log(area)          //get wrapper childrens         const children = object.keys(areas).map(function(key) {           const child = areas[key];            if(child["type"] != "home"){             if(child["parent"]["id"] == area["id"] && leafs.indexof(child["type"]) > -1){               console.log(child);               //return <area key={"area_index_"+key} areadata={area} />             }           }         });         console.log("endfloor/")         //return <area key={"area_index_"+key} areadata={area} />       }   } else {       //not in array    } }); 

is there way better having 1 map inside map?

basicly areas in 1 object, , want match them eachother, looking ["parent"]["id"] match ["id"].

tell me if need more description.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -