2013-11-15 81 views
0

我需要一些幫助將一些javascript轉換爲與coffeescript一起使用的燼。具體來說就是計算屬性。我有以下的javascript代碼:Coffescript和Ember.js計算屬性

Portal.AppsController = Ember.ArrayController.extend({ 
    sortProperties: ['name'], 
    sortAscending: true, 

    appsCount: function() { 
     return this.get('model.length'); 
    }.property('@each'), 

    updated: function() { 
     return this.get('model.modified'); 
    }.property('modified') 
}); 

什麼,我想這樣做簡直就是:

removed for brevity 
... 
appsCount: -> 
    @get 'model.length' 
.property '@each' 
... 

但這不是有效的語法。這實際上可能嗎?

+0

可能重複[Ember在Coffeescript中計算的屬性](http://stackoverflow.com/questions/12777782/ember-computed-properties-in-coff eescript)(直接從側欄中的*相關*列表中...) –

+0

謝謝。你是對的。 – tomasbasham

回答

2

對於計算性能,你需要將其包裝

appsCount: (-> 
    @get 'model.length' 
).property '@each' 

http://emberjs.jsbin.com/ikatIwaB/1/edit

daLength: (-> 
    @get 'length' 
).property 'length' 

順便說一句,我知道,使用灰燼腳本幾個人來解決大多數的你可能看到http://emberscript.com/問題

+0

謝謝,我以前試過這個,但是當我嘗試訪問屬性時獲取輸出的是:[object Object]。我不知道這是爲什麼。感謝鏈接到腳本,我會給出一個去 – tomasbasham

+0

真的嗎?我想知道你的轉換器是否打破了它,因爲jsbin轉換器喜歡它(根據上面的例子)。 – Kingpin2k