I think there are three parts to your question:
- how to watch the collection
- observers in general
- Relationship management
collection observation
The @each property helps to observe the properties of elements in the collection: segments.@each.isSelected
observers in general
.observes()by function is an abbreviation for setting the observer function. If your goal for this function is to update the collection, you might be better off using .property()one that sets an observer and treats the function as a property:
selectedSegments: function() {
return this.get('segments').filterProperty('isSelected', true);
}.property('segments.@each.isSelected')
This means that selectedSegments- this is a subset of segments from this object that are selected and automatically controlled as elements are deleted or marked.
relationship management
Ember , ..
segments = Em.A(),
Ember Objects Ember Models. Ember Data - , . Ember - :
App.Source = DS.Model.extend({
segments: DS.hasMany('segments'),
selectedSegments: function() {
return this.get('segments').filterProperty('isSelected', true);
}.property('segments.@each.isSelected')
});
App.Semgent
App.Segment = DS.Model.extend({
selection: DS.belongsTo('selection')
});