1

这似乎很明显。我不知道我哪里错了。

在控制器中,对于计算属性:

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

我可以在我的模板中要求一个属性。

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

返回“23424”

但是,如果我尝试

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

我收到错误“未捕获的类型错误:无法调用未定义的方法'get'”最终我想做类似的事情

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')
4

1 回答 1

0

我的猜测是 ArrayController 的内容是异步填充的,尽管最终最终是该计算属性返回的值(具有与之关联的答案),但当计算属性首先触发时,没有一个匹配的值,所以它返回未定义的,当然,你不能调用.get()未定义的值。由于您使用的是咖啡脚本,因此您可以这样做:

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

如果返回的值是真实的?,则表示仅尝试方法调用findBy()

于 2014-01-20T20:36:03.643 回答