【问题标题】:How to write .property() with coffee script in Ember? [duplicate]如何在 Ember 中用咖啡脚本编写 .property()? [复制]
【发布时间】:2014-12-30 20:57:26
【问题描述】:

当我想用咖啡脚本编写控制器属性的 .property() 时,咖啡编译总是失败:

App.TestController = Em.Controller.extend
    fullName: ->
        (@get 'name') + 123
    .property 'name'

当我编译上面的代码时,控制台总是报告 .property('name') 错误的错误 在Javascript中,我会这样写:

App.TestController = Em.Controller.extend({
    fullName: function() {
        return this.get('name') + 123;
    }.property('name')
});

有没有办法用咖啡脚本写这个?谢谢

【问题讨论】:

  • 请注意提问时侧边栏中显示的类似问题列表,重复项位于列表顶部。

标签: ember.js coffeescript


【解决方案1】:

到目前为止我发现的最干净的方法是:

App.TestController = Em.Controller.extend
    fullname: (->
        @get('name') + 123
    ).property('name')

它会用一组额外的括号包裹你的函数,但一切仍将按预期工作。

【讨论】:

  • 真的可以解决我的问题,谢谢
猜你喜欢
  • 2014-06-27
  • 1970-01-01
  • 2011-11-17
  • 1970-01-01
  • 2011-06-30
  • 2014-06-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多