Emberjs - 如何正确修改已在控制器中设置为属性的模型上的记录? [英] Emberjs - how to properly modify records on a model that has been set as a property in the controller?

查看:101
本文介绍了Emberjs - 如何正确修改已在控制器中设置为属性的模型上的记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的模板:

    {{#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 记录,并使新的模板可用于模板?

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

从路由器:

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;


推荐答案

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

这篇关于Emberjs - 如何正确修改已在控制器中设置为属性的模型上的记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆