我一直在阅读文档和API,很难找到对以下内容的解释:
export default Ember.Controller.extend({
collectionTotal: function() {
var games = this.get('model');
return games.length
}.property('@each')
});.property('@each')到底是怎么回事?我知道我要拿回计算的属性,我不明白@each是什么。
发布于 2015-08-12 03:42:47
什么是@each**?**
@each观察数组中每个项的各个属性。
例如,如果我观察到users.@each.name,我将收到一个事件,如果:
users属性被替换,例如this.set('users', ...)users中添加或删除项name属性对任何项都有更改可以使用以下语法观察多个属性:users.@each.{name,email}
你不能给它们筑巢。这不起作用:users.@each.friends.@each.mood
请参阅更多正式文件:
回答您的问题
@each本身是没有意义的。如果只需要观察添加或删除的项,则可以观察[]属性。
通常,您应该观察函数正文中使用的相同属性。在您的示例中,这将是model和length
collectionTotal: function() {
var games = this.get('model');
return games.get('length');
}.property('model.length')或相当于:
collectionTotal: function() {
return this.get('model.length');
}.property('model.length')或相当于:
collectionTotal: Ember.computed.reads('model.length')https://stackoverflow.com/questions/31951925
复制相似问题