3

我正在使用 ember-data 12 我有 2 个模型,它们一起加载:

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
        }
    });
4

1 回答 1

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 及更高版本中将不起作用(像这样)。

于 2013-09-22T04:59:42.910 回答