问题
My template:
{{#each test11}}
{{businessname}}
{{/each}}
My controller that works:
// businessmatches is a model that is set as a controller property in the router
test11: function () {
var raw = this.get('businessmatches');
// I want to be able to get all the records, filter them etc etc and then
// make them available to the template
return [
Ember.Object.create(raw.content.get(0)._data)
];
}.property('businessmatches'),
raw.content.get(0)._data
feels like a hack, so I must be missing the proper way of doing this. How can I work with businessmatches
records properly and make the new set available on the template?
Edit
From the router:
setupController: function(controller, model) {
controller.set('businessmatches', this.store.all('businessmatch'));
}
The model:
import DS from 'ember-data';
var Businessmatch = DS.Model.extend({
businessname: DS.attr('string'),
type: DS.attr('string')
});
export default Businessmatch;
回答1:
test11: function(){
// give me all the records that have the property foo that is 11
var bms = this.get('businessmatches').filterBy('foo', 11);
// give me all the records that have the property bar that is 12
bms = bms.filterBy('bar', 12);
// other filtering etc
return bms;
// watch foo/bar on each record, if they change, recompute this computed property
}.property('businessmatches.@each.{foo,bar,...}')
来源:https://stackoverflow.com/questions/25756465/emberjs-how-to-properly-modify-records-on-a-model-that-has-been-set-as-a-prope