can.List
inherits: can.Map
Use for observable array-like objects.
new can.List([array])
Create an observable array-like object.
Parameters
-
array
{Array}
OptionalItems to seed the List with.
Returns
{can.List}
An instance of can.List
with the elements from array.
new can.List(deferred)
Parameters
-
deferred
{can.Deferred}
A deferred that resolves to an array. When the deferred resolves, its values will be added to the list.
Returns
{can.List}
An initially empty can.List
.
Use
can.List
is used to observe changes to an Array.can.List
extendscan.Map
, so all the ways that you're used to working with Maps also work here.Use attr to read and write properties of a list:
Just as you shouldn't set properties of an Map directly, you shouldn't change elements of a List directly. Always use
attr
to set the elements of a List, or use push, pop, shift, unshift, or splice.Here is a tour through the forms of
can.List
'sattr
that parallels the one found under attr:Listening to changes
As with
can.Map
s, the real power of observable arrays comes from being able to react to changes in the member elements of the array. Lists emit five types of events:This example presents a brief concrete survey of the times these events are fired:
More information about binding to these events can be found under attr.