0

我正在使用 ember.js 1.0(pre 4)和 ember-data rev 11

我有一个数据模型需要公开一个列表,该列表是一个静态数组(当时已经在内存中)和一个承诺(将返回相关 ember 数据模型的列表)的组合。

App.Day = DS.Model.extend({
    appointments: function() {
        //this will hit a backend server so it's slow
        return App.Appointment.find();
    }.property(),
    slots: function() {
        //no need to hit a backend server here so it's fast
        return App.Slot.all();
    }.property(),
    combined: function() {
        //return a list of both slots + appointments after some logic is applied
    }.property()
});

当约会实际上是一个承诺,因为它们是按需加载的,我如何在一个属性中结合插槽和约会。

我需要在这个组合属性中做一些逻辑,所以这两个数组的简单合并并不理想。先感谢您!

4

1 回答 1

2

简单的解决方案是从AdapterPopulatedRecordArray返回的对象中获取App.Appointment.find()并添加对象,例如:RecordArrayApp.Slot.all()

combined: function() {
    //return a list of both slots + appointments after some logic is applied
    var apts = this.get('apppointments'),
    slots = this.get('slots');
    apts.addObjects(slots);

    return apts;

}.property('appointments', 'slots')
于 2013-02-06T20:57:26.807 回答