replace
can.List.prototype.replace
Replace all the elements of a List.
list.replace(collection)
Parameters
-
collection
{Array | can.List | can.Deferred}
the collection of new elements to use If a can.Deferred is passed, it must resolve to an
Array
orcan.List
. The elements of the list are not actually removed until the Deferred resolves.
replace
replaces all the elements of this List with new ones.replace
is especially useful whencan.List
s are live-bound intocan.Control
s, and you intend to populate them with the results of acan.Model
call:Learn more about making Lists of models.
Events
A major difference between
replace
andattr(newElements, true)
is thatreplace
always emits an add event and a remove event, whereasattr
will cause set events along with an add or remove event if needed. Corresponding change and length events will be fired as well.The differences in the events fired by
attr
andreplace
are demonstrated concretely by this example: