Ember计算Coffeescript中的属性

Ara*_*ras 17 coffeescript ember.js

我想在Coffeescript中实现以下Javascript代码

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'    
}); 
Run Code Online (Sandbox Code Playgroud)

以下是我目前在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'    
)
Run Code Online (Sandbox Code Playgroud)

我明白了:

Error: Parse error on line 11: Unexpected '.'
Run Code Online (Sandbox Code Playgroud)

问题似乎与点在.property('content.id') .我不知道这是如何转化为Coffeescript的.如何在Coffeescript中正确实现此视图?

sly*_*7_7 42

它已经很长一段时间了,但我认为这应该是这样写的:

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'    
)
Run Code Online (Sandbox Code Playgroud)