以下函数需要返回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');
});
},