Reputation: 127
I have an nested data structure as follows:
Job:{
JobId: 1,
NumberTrackr: 2,
Trackrs: [
1 : { TaskTrackrID: a,
NumberSlots:1,
slots: [
slot1: {uniqueId:foo, you: get, the:[point, by, now]}
]
},
2 : { TaskTrackrID: b,
NumberSlots:1,
slots: [
slot1: {uniqueId:bar, you: get, the:[point, by, now]}
]
}
]
}
And my application uses this data hierarchy (calculating the sum of a specific Trackr's 'children's' foo attribute) as well as each data level as a whole (for example, calculating statistics from the content of all slots regardless of their 'parent' TaskTracker).
Im new to Ember, but my I was thinking of creating a model for each object level (TaskTrackr, Slot etc). This model would consist of all the attributes shown above as in addition to some sort of array of sub models (using arraycontroller?). Said submodels would also have attributes as well as their own array of sub models. It is important that the highe level objects can have computed properties calculated from their sub objects. It is also important that I can access each level as a whole and modify specific attributes.
What would the code look like that would enable me to access this data both as a tree as well as on a level basis?
Thank you so much for your help
Upvotes: 1
Views: 1589
Reputation: 3594
Take a look at Ember Data. It supports these types of relationships.
App.Job = DS.Model.extend({
trackers: DS.hasMany('App.Tracker')
})
App.Tracker = DS.Model.extend({
job: DS.belongsTo('App.Job');
})
// ... and so on
var job = App.Job.createRecord();
job.get('trackers').pushObject(App.Tracker.createRecord());
Just to note. You mentioned using ArrayController
and you will likely use that inside of your Ember application. However, when modeling your data/relationships you will not use any controllers. You should be able to do do what you pasted above with using only DS.Model
Upvotes: 2