0

I'm using Backbone and Underscore. My objects look something like:

TopObject: {
name: '',
middleObjects: []
}

MiddleObject: {
name: '',
bottomObjects: []
}


BottomObject: {
name:'',
someOtherProp: ''
}

So basically if you have one topObject, it will have multiple middle objects as one of its properties, and the middleObjects will have multiple bottomObjects as one of its properties.

I'm not really sure how I can display these fields in a table. So I got this far using underscore.

var someTopObject = new TopObject(); // that has real data
_.each(someTopObject.get('middleObjects'), function (midObjs) {
  // do something with MidObj.name
  // not sure how to get midObjs.bottomObjects
});

Right now I Know that bottomObjects can only have 2 items. So I guess I could hardcode getting the first and second object in bottomObjects, but I was unsure if there was a more elegant way. Thanks!

1 Answer 1

1

Nest the loops?

_.each(someTopObject.get('middleObjects'), function (midObj) {
    _.each(midObj.get('bottomObjects'), function (bottomObj) {
        // do stuff
    });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.