Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
564 views
in Technique[技术] by (71.8m points)

根据对象里面某个值做判断,当有id重复的时候,当前对象覆盖之前的对象

let obj = {
    column:{
        __id:'1',
        align: "center"
        className: "test-name"
        key: "singlePrice",
        ....

    },
    index: 0
    row:{
        applyNum: 1
        brandName: "世达"
        brandPk: "ca36dcac632c4dc0b704aaa88ec01fdb"
        categoryName: "物料类1",
        ...
    }
}

let obj2 = {
    column:{
        __id:'1',
        align: "center"
        className: "test-name"
        key: "singlePrice",
        ....
    },
    index: 1
    row:{
        applyNum: 2
        brandName: "11"
        brandPk: "ca36dcac632c4dc0b704aaa88ec01fdb"
        categoryName: "物料类2",
        ...
    }
}

先有一个obj ,当我获取了第二个obj2的时候,里面column.__id是一样的,怎么样判断让obj2覆盖obj的呢


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Object.assign(obj,obj2) 对象合并


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...