updateDeep
Recursively updates a list with new values or new property values.
list.updateDeep(newItems)
Similar to .update(), .updateDeep()
will
overwrite values within list
with values from newItems
. Where update()
will replace
values or properties one level deep, .updateDeep()
will overwrite values or
properties on objects and lists recursively.
The following will:
- remove
payal
frompeople
, - set
justin
'sname
to"JUSTIN"
, and - remove
justin
'sage
property:
import {DefineMap, DefineList} from "can";
const justin = new DefineMap({name: "Justin", age: 35}),
payal = new DefineMap({name: "Payal", age: 35});
const people = new DefineList([justin, payal]);
people.updateDeep([
{name: "JUSTIN"}
]);
console.log( justin.serialize(), payal.serialize() );
//-> {name: "JUSTIN"}, {age: 35, name: "Payal"}
console.log( people.serialize() ) //-> [
// {name: "JUSTIN"}
// ]
Use .assignDeep() if you want recursive updating that doesn't remove properties. Use can-diff/merge-deep/merge-deep if you want recursive updating that is identity aware.
Parameters
- newItems
{Array|Object}
:A list or array of values, or an object of property values. If an object is passed, the properties of the list will be updated with the values in
newItems
.