Enumerable

Ember.Enumerable Class

PRIVATE

Defined in: packages/ember-runtime/lib/mixins/enumerable.js:62

Module: ember-runtime

This mixin defines the common interface implemented by enumerable objects in Ember. Most of these methods follow the standard Array iteration API defined up to JavaScript 1.8 (excluding language-specific features that cannot be emulated in older versions of JavaScript).

This mixin is applied automatically to the Array class on page load, so you can use any of these methods on simple arrays. If Array already implements one of these methods, the mixin will not override them.

Writing Your Own Enumerable

To make your own custom class enumerable, you need two items:

  1. You must have a length property. This property should change whenever the number of items in your enumerable object changes. If you use this with an Ember.Object subclass, you should be sure to change the length property using set().

  2. You must implement nextObject(). See documentation.

Once you have these two methods implemented, apply the Ember.Enumerable mixin to your class and you will be able to enumerate the contents of your object like any other collection.

Using Ember Enumeration with Other Libraries

Many other libraries provide some kind of iterator or enumeration like facility. This is often where the most common API conflicts occur. Ember's API is designed to be as friendly as possible with other libraries by implementing only methods that mostly correspond to the JavaScript 1.8 API.

doc_EmberJs
2016-11-30 16:51:54
Comments
Leave a Comment

Please login to continue.