An ArrayController provides a way for you to publish an array of objects for CollectionView or other controllers to work with. To work with an ArrayController, set the content property to the array you want the controller to manage. Then work directly with the controller object as if it were the array itself.
When you want to display an array of objects in a CollectionView, bind the "arrangedObjects" of the array controller to the CollectionView's "content" property. This will automatically display the array in the collection view.
Defined in: array.js
- SproutCore 1.0
- Fields borrowed from SC.Controller:
- Fields borrowed from SC.Object:
- concatenatedProperties, isDestroyed, isObject, nextProperty, object, property, target, toInvalidate
- Fields borrowed from SC.Observable:
- Fields borrowed from SC.Array:
- Fields borrowed from SC.Enumerable:
- indexOf(object, startAt)
Field DetailallowsSingleContent Boolean
YES if you want the controller to wrap non-enumerable content
in an array and publish it. Otherwise, it will treat single content like
The content array managed by this controller.
You can set the content of the ArrayController to any object that
SC.Enumerable. If you set the content to an object
SC.Enumerable only, you must also set the
so that the ArrayController can order the enumerable for you.
If you set the content to a non-enumerable and non-array object, then the ArrayController will wrap the item in an array in an attempt to normalize the result.
YES if you want objects removed from the array to also be
deleted. This is a convenient way to manage lists of items owned
by a parent record object.
Note that even if this is set to
destroyObject() instead of
removeObject() will still destroy the object in question as well as
removing it from the parent array.
Makes the array editable or not. If this is set to
NO, then any attempts
at changing the array content itself will throw an exception.
Used to sort the array.
If you set this property to a key name, array of key names, or a function, then then ArrayController will automatically reorder your content array to match the sort order. When using key names, you may specify the direction of the sort by appending ASC or DESC to the key name. By default sorting is done in ascending order.
myController.set('orderBy', 'title DESC'); myController.set('orderBy', ['lastName ASC', 'firstName DESC']);
Normally, you should only use this property if you set the content of the
controller to an unordered enumerable such as
In this case the
orderBy property is required in order for the controller
to property order the content for display.
If you set the content to an array, it is usually best to maintain the
array in the proper order that you want to display things rather than
using this method to order the array since it requires an extra processing
step. You can use this
orderBy property, however, for displaying smaller
arrays of content.
Note that you can only use
addObject() to insert new objects into an
array that is ordered. You cannot manually reorder or insert new objects
into specific locations because the order is managed by this property
If you pass a function, it should be suitable for use in compare().
Instance Method Detail
Adds an object to the array. If the content is ordered, this will add the object to the end of the content array. The content is not ordered, the location depends on the implementation of the content.
If the source content does not support adding an object, then this method will throw an exception.
SC.Array object suitable for use in a CollectionView.
Depending on how you have your ArrayController configured, this property
may be one of several different values.
Computed property insides whether you can add content. You can add
content as long as the controller
isEditable and the content is not a
Note that the only way to simply add object to an ArrayController is to
pushObject() methods. All other methods imply
reordering and will fail.
Computed property indicates whether or not the array controller can
remove content. You can delete content only if the content is not single
Computed property indicates whether you can reorder content. You can
reorder content as long a the controller
isEditable and the content is a
SC.Array-like object. You cannot reorder content when
YES if the controller has valid content that can be displayed,
even an empty array. Returns NO if the content is null or not enumerable
allowsSingleContent is NO.
Removes the passed object from the array. If the underlying content
is a single object, then this simply sets the content to null. Otherwise
it will call
removeObject() on the content.
YES, this will actually destroy the object.
Returns the current status property for the content. If the content does
not have a status property, returns