0

私はember.js1.0(pre 4)とember-datarev11を使用しています

静的配列(その時点ですでにメモリ内にある)とpromise(関連する残り火データモデルのリストを返す)の組み合わせであるリストを公開する必要があるデータモデルがあります。

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

アポイントメントがオンデマンドでロードされるため、アポイントメントが事実上約束である場合、プロパティでスロットとアポイントメントの両方をどのように組み合わせることができますか。

この結合されたプロパティでいくつかのロジックを実行する必要があるため、これら2つの配列の単純なマージは理想的ではありません。前もって感謝します!

4

1 に答える 1

2

簡単な解決策は、AdapterPopulatedRecordArrayによって返されApp.Appointment.find()たオブジェクトをRecordArrayによって返されApp.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 に答える