Emberjs - how to properly modify records on a model that has been set as a property in the controller?

非 Y 不嫁゛ 提交于 2020-01-05 07:49:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!