2014-01-20 39 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。