在Ember.js中迭代相关模型

在Ember.js中迭代相关模型,ember.js,Ember.js,我有以下模型,它们具有基本的关联,如您所见: App.PricingSummary = DS.Model.extend({ startDate: DS.attr(), endDate: DS.attr(), days: DS.hasMany('day', {async: true}) }); App.Day = DS.Model.extend({ date: DS.attr(), rate: DS.belongsTo('rate', {async: tr

我有以下模型,它们具有基本的关联,如您所见:

App.PricingSummary = DS.Model.extend({
    startDate: DS.attr(),
    endDate: DS.attr(),
    days: DS.hasMany('day', {async: true})
});

App.Day = DS.Model.extend({
    date: DS.attr(),
    rate: DS.belongsTo('rate', {async: true})
});

App.Rate = DS.Model.extend({
    price: DS.attr()
});
这里的概念是,
PricingSummary
包含一组
s,每个天都有一个
费率
,这基本上是当天的价格<代码>比率需要是它自己的模型,因为应该有一组有限的值,从中分配给一天

我要做的是在我的控制器中,它有一个
PricingSummary
模型的上下文,循环通过
PricingSummary
中的
Day
s,找到该期间的最低
费率

以下是我的尝试:

barRange: function(){
    var lowBar;

    this.get('days').then(function(days){

        days.forEach(function(day){

            day.get('rate').then(function(rate){
                rateValue = rate.get('price')

                if(typeof lowBar === 'undefined' || rateValue < lowBar){
                    lowBar = rateValue;
                }
            });

        });

        console.log( 'lowBar is ' + lowBar )
    });

}.property('days')
barRange:function(){
var-lowBar;
this.get('days')。然后(函数(days){
天。forEach(函数(天){
day.get('rate')。然后(函数(rate){
rateValue=rate.get('价格')
if(低条类型===‘未定义’| |比率值<低条){
lowBar=额定值;
}
});
});
console.log('lowBar is'+lowBar)
});
}.property(“天”)

我认为这真的只是半生不熟。。。但它向你展示了我处理这件事的方式,这可能是完全错误的,也可能不是完全错误的。有更好的方法吗?如果没有,我在这里缺少的最后几部分是什么?

你的路线是什么样子的?
App.PropertyPricingRoute=Ember.Route.extend({
返回这个.store.find('pricingSummary',1);
})这是有问题的路线,所以这个模型是一个
pricingSummary
,我正试图解决这个问题