Alp*_*pha 5 javascript properties ember.js
我环顾四周,但我找不到任何关于以下内容之间实际差异的文件.
Ember.Object.extend({
// ...
myProperty1: function() { /* ... */ }.property('myArray'),
myProperty2: function() { /* ... */ }.property('myArray.content'),
myProperty3: function() { /* ... */ }.property('myArray.[]'),
myProperty4: function() { /* ... */ }.property('myArray.@each')
});
Run Code Online (Sandbox Code Playgroud)
我确实理解这.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')
});
Run Code Online (Sandbox Code Playgroud)
我还要指出,如果您忘记使用 Ember 的方法之一,而只是使用简单的 JavaScript 更新数组,如下所示:
this.myArray = [];
Run Code Online (Sandbox Code Playgroud)
这些计算属性都不会被更新。
| 归档时间: |
|
| 查看次数: |
116 次 |
| 最近记录: |