如何从Ember-data获取父模型

时间:2013-07-23 22:05:30

标签: ember.js ember-data

我使用的是ember-data 12 我有两个模型,它们共同载入:

App.Store = DS.Store.extend({
    revision: 12,
    adapter: App.Adapter.create()
});

App.Propose = DS.Model.extend({
    meeting: DS.belongsTo('App.Meeting'),   
    time: DS.attr('string'), 
});


App.Meeting = DS.Model.extend({

    name: DS.attr('string'),
    proposes: DS.hasMany('App.Propose'),


});

我如何通过建议模型与某些计算字段进行会面:

App.Propose = DS.Model.extend({
        meeting: DS.belongsTo('App.Meeting'),   
        time: DS.attr('string'), 
        someCalc:function(){
           this.get('meeting').get('name') //I want that. but its not worked
        }
    });

1 个答案:

答案 0 :(得分:0)

你这样做的方式是:

App.Propose = DS.Model.extend({
     meeting: DS.belongsTo('App.Meeting'),   
     time: DS.attr('string'), 
     someCalc:function(){
        return this.get('meeting.name'); // or do whatever operation you need in here
     }.property('meeting.name')
 });

但是Ember Data已经发展了很多,这在Beta 2及更高版本中不起作用(如此)。