本文介绍了Ember在Coffeescript中计算的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  App.ItemView = Ember.View.extend({
classNameBindings:['itemId']​​,
itemId:function(){
console.log(this.get('content'));
returnitem - %@。 fmt(this.get('content.id'));
} .property('content.id'),
templateName:'item'
});

这里是我到目前为止在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'

我得到:

 错误:第11行解析错误:意外的'。 b $ b  

问题似乎是在 .property('content.id ')
。我不知道这如何翻译成Coffeescript。如何在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'

/ pre>

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'    
}); 

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

I get:

Error: Parse error on line 11: Unexpected '.'

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

这篇关于Ember在Coffeescript中计算的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 20:29