2012-03-13 76 views

回答

5

是的,這是可能的。但是,您忘記了return您的計算數組,並且您必須將cacheable()添加到計算屬性,該屬性返回一個對象而不是基元。否則,你會遇到一個無限循環(參見討論https://github.com/emberjs/ember.js/issues/38)還可以看看Gordon Hempton出色的blog post關於當前的Ember.js問題,其中包括有關計算屬性的問題。但是,自承諾626d23f緩存問題已解決。

一個修正你的代碼的例子是在這裏:http://jsfiddle.net/gh7Qr/4/

把手:

<script type="text/x-handlebars" > 
    {{#each App.games}} 
     {{this}} 
    {{/each}} 
    {{#each App.gamesA}} 
     {{this}} 
    {{/each}} 
</script> 

的JavaScript:

App = Ember.Application.create({ 
    games: [1, 2, 3], 
    gamesA: Em.computed(function() { 
     return this.get('games').map(function(game) { 
      return game + 'a'; 
     }) 
    }).property('games').cacheable() 
});​ 

+0

謝謝!我正在翻譯咖啡標記,並忘記了返回。緩存是什麼讓我 – 2012-03-13 16:20:31

相關問題