Not sure if this will help, but something that I did with nested objects:
object = { children: [], // array of similar objects with children property and update function update: function(data){ // update this item this.data = data; // update each immediate child if (this.children) for (var i in this.children) this.children[i].update(data); } }; // then you just call update on the first item: object.update(data);
If you follow this pattern, instead of setting up complex loops at the root level, you simply iterate over the immediate children and call their update function, which then pushes through their children and goes all the way down.
I am not a great JS developer, only what I did for some nested comments that I worked with on another day;)
source share