参考文档:https://facebook.github.io/react/docs/update.html
react/lib/update 与 react-addons-update 等价
包含
apply,
set,
push,
unshift,
splice,
merge 方法,用以不改变原来数据,返回新的数据
apply:函数,入参是原始值,返回结果
push:数组后插入
push:数组前插入
splice:数组任意位置插入或删除
$merge:合并对象
demo
var x = {
cards: [{
name: "a",
id: 1
}, {
name: "b",
id: 2
}, {
name: "c",
id: 3
}, {
name: "d",
id: 4
}]
}
var z = update(x, {
cards: {
// 数组中的第三个
3:{ id:{
$apply: function(x) {return x * 2;}
}}
},
});