Last active
January 11, 2016 04:05
-
-
Save denzo/fe54e72463d0cd17d9a0 to your computer and use it in GitHub Desktop.
Computed Properties with @each
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName:'Ember Twiddle', | |
owner: Ember.computed(function() { | |
return this.store.createRecord('owner'); | |
}), | |
allItems: Ember.computed(function() { | |
return [ | |
Ember.Object.create({id: 0, status: 'clean'}), | |
Ember.Object.create({id: 1, status: 'clean'}), | |
Ember.Object.create({id: 2, status: 'clean'}), | |
Ember.Object.create({id: 3, status: 'clean'}), | |
Ember.Object.create({id: 4, status: 'dirty'}), | |
]; | |
}), | |
cleanItems: Ember.computed('[email protected]',function() { | |
return this.get('allItems').filterBy('status', 'clean'); | |
}), | |
dirtyItems: Ember.computed('[email protected]',function() { | |
return this.get('allItems').filterBy('status', 'dirty'); | |
}), | |
actions: { | |
addCleanItem() { | |
this.store.createRecord('item', { | |
owner: this.get('owner'), | |
status: 'clean' | |
}) | |
}, | |
addDirtyItem() { | |
this.store.createRecord('item', { | |
owner: this.get('owner'), | |
status: 'dirty' | |
}) | |
}, | |
updateItem(item, status) { | |
console.log(item); | |
item.set('status', status); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DS from 'ember-data'; | |
export default DS.Model.extend({ | |
owner: DS.belongsTo('owner'), | |
status: DS.attr('string') | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DS from 'ember-data'; | |
export default DS.Model.extend({ | |
items: DS.hasMany('item'), | |
cleanItems: Ember.computed('[email protected]',function() { | |
return this.get('items').filterBy('status', 'clean'); | |
}), | |
dirtyItems: Ember.computed('[email protected]',function() { | |
return this.get('items').filterBy('status', 'dirty'); | |
}), | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.4.17", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.2.0", | |
"ember-data": "2.2.0", | |
"ember-template-compiler": "2.2.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment