Skip to content

Instantly share code, notes, and snippets.

@ngot
Created March 6, 2014 05:10
Show Gist options
  • Save ngot/9382990 to your computer and use it in GitHub Desktop.
Save ngot/9382990 to your computer and use it in GitHub Desktop.
var structure = {
"root":{
"name":"Main Level",
"god": "is a girl",
nodes:{
"node1":{
"name":"Node 1"
},
"node2":{
"name":"Node 2"
},
"node3":{
"name":"Node 3"
}
}
}
}
var setParent = function(o){
if(o.nodes != undefined){
for(n in o.nodes){
o.nodes[n].parent = o;
setParent(o.nodes[n]);
}
}
}
setParent(structure);
var node2 = structure.root.nodes["node2"];
console.log(node2.parent.name);
var node3 = structure.root.nodes.node3;
console.log(node3.parent.god);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment