加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

使用react/lib/update 对数据进行操作

发布时间:2020-12-15 07:33:09 所属栏目:百科 来源:网络整理
导读:参考文档:https://facebook.github.io/react/docs/update.html react/lib/update 与 react-addons-update 等价 包含 a p p l y , set, p u s h , unshift, s p l i c e , merge 方法,用以不改变原来数据,返回新的数据 a p p l y : 函 数 , 入 参 是 原

参考文档: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;}
                }}
            },});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读