2014-01-20 37 views
1

这看起来好像很明显。我不知道我要去哪里错。Ember Array调用getBy上的返回返回undefined

在控制器

,对于计算性能:

totalMonthlyEsales: (-> 
    @findBy('key', 'value1') 
).property('@each.answer') 

我可以要求我的模板罚款此属性。

<div>{{totalMonthlyEsales.answer}}</div> 

返回“23424”

但是,如果我尝试

totalMonthlyEsales: (-> 
    @findBy('key', 'value1').get('answer') 
).property('@each.answer') 

我得到的错误“遗漏的类型错误:无法调用的未定义‘得到’” 最后,我想要做的事像

totalMonthlyEsales: (-> 
    parseInt @findBy('key', 'value1').get('answer') 
).property('@each.answer') 

plccDcSalesCash: (-> 
    parseInt @findBy('key', 'value2').get('answer') 
).property('@each.answer') 

otherTenderTypes: (-> 
    @get('plccDcSalesCash') - @get('totalMonthlyEsales') 
).property('totalMonthlyEsales', 'plccDcSalesCash') 
+1

这属于Coffeescript?...这就像在C下发布C++,因为它只是C. – elclanrs

回答

0

我的猜测是ArrayC的内容ontroller异步填充,尽管最终结果是由该计算属性返回的值(具有与其相关的答案),当计算属性首先触发时,不存在匹配值,因此它返回未定义的值当然,您不能在未定义的值上调用.get()。既然你在CoffeeScript中的时候,你可以只是这样做:

totalMonthlyEsales: (-> 
    @findBy('key', 'value1')?.get('answer') 
).property('@each.answer') 

?说,只有尝试方法调用,如果返回的值从findBy()是truthy。