如何从函数返回Ember.RSVP.all的结果?

时间:2015-04-30 22:50:26

标签: ember.js ember-data

以下函数需要返回true或false。在函数底部的then调用内,我从result.isAny('hasOverride')获取了我需要的值,但我不知道如何从hasRoomUpcharge函数返回此值。我该怎么做呢?我想在return前面添加Ember.RSVP.all可以做到,但它不起作用。请帮忙!

hasRoomUpcharge: function(roomRates, defaultRoomTypeCode){
    var defaultRoomRates = roomRates.findBy('roomTypeCode', defaultRoomTypeCode);
    var nonDefaultRoomRates = roomRates.rejectBy('roomTypeCode', defaultRoomTypeCode);
    var nonDefaultRoomMasters = this.modelFor('propertyPricing').roomTypeMasters.rejectBy('isDefault');

    var promises = [];
    var promise;

        nonDefaultRoomMasters.forEach(function(roomMaster){
            var roomTypeCode = roomMaster.get('roomTypeCode');

             promise = roomMaster.get('roomRateUpcharge').then(function(roomRateUpcharge){
                var currentRoomMasterOnePersonPrice = nonDefaultRoomRates.findBy('roomTypeCode', roomTypeCode).onePersonPrice;
                var defaultRoomMasterOnePersonPrice = defaultRoomRates.onePersonPrice;
                var roomUpcharge = roomRateUpcharge.get('onePersonRateUpcharge');

                if(currentRoomMasterOnePersonPrice != defaultRoomMasterOnePersonPrice + roomUpcharge){
                    return { hasOverride: true };
                }
                else {
                    return { hasOverride: false };
                }
            });

            promises.push(promise);
        });


        return Ember.RSVP.all(promises).then(function(result){
            return result.isAny('hasOverride');
        });
},

0 个答案:

没有答案