can.List
2.0
inherits: can.Map
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 for observable array-like objects.
Use
can.Listis used to observe changes to an Array.can.Listextendscan.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
attrto set the elements of a List, or use push, pop, shift, unshift, or splice.Here is a tour through the forms of
can.List'sattrthat parallels the one found under attr:Listening to changes
As with
can.Maps, 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.