Javascript 什么';s[]、@each、content和<;arrayName>;在恩伯斯?
我四处查看了一下,但找不到任何关于以下各项之间实际差异的好文档:Javascript 什么';s[]、@each、content和<;arrayName>;在恩伯斯?,javascript,ember.js,properties,Javascript,Ember.js,Properties,我四处查看了一下,但找不到任何关于以下各项之间实际差异的好文档: Ember.Object.extend({ // ... myProperty1:function(){/*…*/}.property('myArray'), myProperty2:function(){/*…*/}.property('myArray.content'), myProperty3:function(){/*…*/}.property('myArray.[]'), myProperty4:function(){/
Ember.Object.extend({
// ...
myProperty1:function(){/*…*/}.property('myArray'),
myProperty2:function(){/*…*/}.property('myArray.content'),
myProperty3:function(){/*…*/}.property('myArray.[]'),
myProperty4:function(){/*…*/}.property('myArray.@each')
});
我知道.content
似乎是属性数组的内部存储,如果这恰好是PromiseArray
,则可能不可用。我还了解到,@each
不会以这种方式使用,而是主要用于访问ProxyArray
,该数组通过映射该数组中每个元素的内部属性生成结果
除了这些细微的差别,它们的作用似乎几乎相同。但是myArray
和myArray.[]
呢?和其他人相比,他们呢
Ember.Object.extend({
// ...
// Updates if myArray is set to a new value using .set
myProperty1: function() { /* ... */ }.property('myArray'),
// Updates if myArray is an Ember Object (like an ArrayController)
// and its 'content' property is set to a new value using
// .set('content', newArray) or .replaceContent(...)
// which can also happen implicitly
// Also note that for an ArrayController 'content' is an alias of 'model'
myProperty2: function() { /* ... */ }.property('myArray.content'),
// Updates if myArray is an Ember Array or ArrayProxy or MutableEnumerable
// and it is 'mutated' using myArray.addObject(s), myArray.removeObject,
// myArray.popObject, myArray.shiftObject, myArray.pushObject(s), etc.
myProperty3: function() { /* ... */ }.property('myArray.[]'),
// Updates if myArray is an Ember Array or ArrayProxy and one of it's
// elements is set to a new value using .set or .replace
// such as this.set('myArray.firstObject', 10) or
// this.get('myArray').replace(2, 1, [10]);
myProperty4: function() { /* ... */ }.property('myArray.@each')
});
我还要注意,如果您忘记使用Ember的方法之一,而只是使用简单的JavaScript更新数组,如下所示:
this.myArray = [];
这些计算属性都不会更新。答案令人印象深刻。直截了当,明白无误。非常感谢你。