ArrayProxy

Ember.ArrayProxy Class

PUBLIC

Extends: Ember.Object

Uses: Ember.MutableArray

Defined in: packages/ember-runtime/lib/system/array_proxy.js:35

Module: ember-runtime

An ArrayProxy wraps any other object that implements Ember.Array and/or Ember.MutableArray, forwarding all requests. This makes it very useful for a number of binding use cases or other cases where being able to swap out the underlying array is useful.

A simple example of usage:

let pets = ['dog', 'cat', 'fish'];
let ap = Ember.ArrayProxy.create({ content: Ember.A(pets) });

ap.get('firstObject');                        // 'dog'
ap.set('content', ['amoeba', 'paramecium']);
ap.get('firstObject');                        // 'amoeba'

This class can also be useful as a layer to transform the contents of an array, as they are accessed. This can be done by overriding objectAtContent:

let pets = ['dog', 'cat', 'fish'];
let ap = Ember.ArrayProxy.create({
    content: Ember.A(pets),
    objectAtContent: function(idx) {
        return this.get('content').objectAt(idx).toUpperCase();
    }
});

ap.get('firstObject'); // . 'DOG'

_contentDidChangeprivate

Defined in packages/ember-runtime/lib/system/array_proxy.js:178

Invoked when the content property changes. Notifies observers that the entire array content has changed.

_contentWillChangeprivate

Defined in packages/ember-runtime/lib/system/array_proxy.js:131

Invoked when the content property is about to change. Notifies observers that the entire array content will change.

contentArrayDidChange (contentArray, start, removeCount, addCount) private

Defined in packages/ember-runtime/lib/system/array_proxy.js:165

Override to implement content array didChange observer.

Parameters:

contentArray Ember-Array
the content array
start Number
starting index of the change
removeCount Number
count of items removed
addCount Number
count of items added

contentArrayWillChange (contentArray, start, removeCount, addCount) private

Defined in packages/ember-runtime/lib/system/array_proxy.js:153

Override to implement content array willChange observer.

Parameters:

contentArray Ember-Array
the content array
start Number
starting index of the change
removeCount Number
count of items removed
addCount Number
count of items added

objectAtContent (idx) Objectpublic

Defined in packages/ember-runtime/lib/system/array_proxy.js:96

Should actually retrieve the object at the specified index from the content. You can override this method in subclasses to transform the content item to something new.

This method will only be called if content is non-null.

Parameters:

idx Number
The index to retrieve.

Returns:

Object
the value or undefined if none found

replaceContent (idx, amt, objects) Voidprivate

Defined in packages/ember-runtime/lib/system/array_proxy.js:112

Should actually replace the specified objects on the content array. You can override this method in subclasses to transform the content item into something new.

This method will only be called if content is non-null.

Parameters:

idx Number
The starting index
amt Number
The number of items to remove from the content.
objects Array
Optional array of objects to insert or null if no objects.

Returns:

Void

arrangedContentprivate

Defined in packages/ember-runtime/lib/system/array_proxy.js:86

The array that the proxy pretends to be. In the default ArrayProxy implementation, this and content are the same. Subclasses of ArrayProxy can override this property to provide things like sorting and filtering.

contentEmber-Arrayprivate

Defined in packages/ember-runtime/lib/system/array_proxy.js:76

The content array. Must be an object that implements Ember.Array and/or Ember.MutableArray.

© 2017 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://emberjs.com/api/classes/Ember.ArrayProxy.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部