attr
Get or set elements in a List.
list.attr()
Gets an array of all the elements in this can.List
.
Returns
{Array}
An array with all the elements in this List.
list.attr(index)
Reads an element from this can.List
.
Parameters
-
index
{Number}
The element to read.
Returns
{*}
The value at index.
list.attr(index, value)
Assigns value to the index index on this can.List
, expanding the list if necessary.
Parameters
-
index
{Number}
The element to set.
-
value
{*}
The value to assign at index.
Returns
{can.List}
This list, for chaining.
list.attr(elements[, replaceCompletely])
Merges the members of elements into this List, replacing each from the beginning in order. If
elements is longer than the current List, the current List will be expanded. If elements
is shorter than the current List, the extra existing members are not affected (unless
replaceCompletely is true
). To remove elements without replacing them, use removeAttr
.
Parameters
-
elements
{Array}
An array of elements to merge in.
-
replaceCompletely
=false
{bool}
Optionalwhether to completely replace the elements of List If replaceCompletely is
true
and elements is shorter than the List, the existing extra members of the List will be removed.
Returns
{can.List}
This list, for chaining.
Use
attr
gets or sets elements on thecan.List
it's called on. Here's a tour through how all of its forms work:Deep properties
attr
can also set and read deep properties. All you have to do is specify the property name as you normally would if you weren't usingattr
.The discussion of deep properties under
attr
may also be enlightening.Events
can.List
s emit five types of events in response to changes. They are:The change event
The first event that is fired is the change event. The change event is useful if you want to react to all changes on an List.
The parameters of the event handler for the change event are:
'add'
,'remove'
, or'set'
.undefined
if elements were removed.undefined
if elements were added.Here is a concrete tour through the change event handler's arguments:
The set event
set events are fired when an element at an index that already exists in the List is modified. Actions can cause set events to fire never also cause length events to fire (although some functions, such as
splice
may cause unrelated sets of events to fire after being batched).The parameters of the event handler for the set event are:
Here is a concrete tour through the set event handler's arguments:
The add event
add events are fired when elements are added or inserted into the List.
The parameters of the event handler for the add event are:
Here is a concrete tour through the add event handler's arguments:
The remove event
remove events are fired when elements are removed from the list.
The parameters of the event handler for the remove event are:
Here is a concrete tour through the remove event handler's arguments:
The length event
length events are fired whenever the list changes.
The parameters of the event handler for the length event are:
stopBatch
was called. Because of this, you may recieve multiple length events with the same length parameter.Here is a concrete tour through the length event handler's arguments: