Coffeescript 中的 Ember 计算属性 [英] Ember computed properties in Coffeescript
本文介绍了Coffeescript 中的 Ember 计算属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 Coffeescript 中实现以下 Javascript 代码
I want to implement the following Javascript code in Coffeescript
App.ItemView = Ember.View.extend({
classNameBindings: ['itemId'],
itemId: function() {
console.log(this.get('content'));
return "item-%@".fmt(this.get('content.id'));
}.property('content.id'),
templateName: 'item'
});
这是我目前在 coffeescript 中的内容:
Here is what I have so far in coffeescript:
App.ItemView = Ember.View.extend(
classNameBindings: ['itemId']
itemId: ->
console.log this.get('content')
contentId = this.get('content.id')
"item-#{contentId}");
.property('content.id')
templateName: 'item'
)
我明白了:
Error: Parse error on line 11: Unexpected '.'
问题似乎与 .property('content.id') 中的点有关代码>.我不知道这如何转化为 Coffeescript.如何在 Coffeescript 中正确实现此视图?
The issue seems to be with the dot in .property('content.id')
. I dont know how this translates into Coffeescript. How can I properly implement this view in Coffeescript?
推荐答案
好久没来了,不过我觉得应该这样写:
It's beeing a quite long time, but I think this should be written like this:
App.ItemView = Ember.View.extend(
classNameBindings: ['itemId']
itemId: (->
console.log this.get('content')
contentId = this.get('content.id')
"item-#{contentId}");
).property('content.id')
templateName: 'item'
)
这篇关于Coffeescript 中的 Ember 计算属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文