Emberjs - 如何正确修改已在控制器中设置为属性的模型上的记录?

时间:2014-09-10 02:36:48

标签: ember.js ember-cli

我的模板:

    {{#each test11}}
        {{businessname}}
    {{/each}}

我的控制器有效:

// 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感觉像是一个黑客,所以我一定错过了这样做的正确方法。如何正确使用businessmatches记录并在模板上提供新的设置?

修改

来自路由器:

setupController: function(controller, model) {
    controller.set('businessmatches', this.store.all('businessmatch'));
}

模特:

import DS from 'ember-data';

var Businessmatch = DS.Model.extend({
    businessname: DS.attr('string'),
    type: DS.attr('string')
});

export default Businessmatch;

1 个答案:

答案 0 :(得分:0)

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,...}')