[英]Replace in array objects with same id using lodash
I am new with loash and need help on this. 我是新手,需要帮助。
i have 2 objects: 我有2个对象:
{
"data": [
{
"RHID": "2",
"NOME": "Leonor",
},
{
"RHID": "3",
"NOME": "José",
}
]
}
and 和
{
"data": [
{
"RHID": "2",
"NOME": "Leonor maria",
},
{
"RHID": "3",
"NOME": "José Leo",
}
]
}
How can i replace inner objects with same RHID if they are diferent. 如果内部对象不同,如何用相同的RHID替换内部对象。 Keep the second.
保持第二。 I remove duplicates with
我删除重复项
Form.myData[Form.arrData] = _.map(
_.uniq(
_.map(Form.myData[Form.arrData], function (obj) {
return JSON.stringify(obj);
})
), function (obj) {
return JSON.parse(obj);
}
);
i want to replace if diferent. 我想更换如果不同。 Thanks a lot .
非常感谢 。
solved with merge the oposite way 用合并相反的方法解决
$.merge( newData[Form.arrData],Form.myData[Form.arrData]);
instead of 代替
$.merge( Form.myData[Form.arrData],newData[Form.arrData]);
and then 接着
Form.myData[Form.arrData] = _.map(
_.uniq(
_.map( newData[Form.arrData], function (obj) {
return JSON.stringify(obj);
})
), function (obj) {
return JSON.parse(obj);
}
);
instead of 代替
Form.myData[Form.arrData] = _.map(
_.uniq(
_.map(Form.myData[Form.arrData], function (obj) {
return JSON.stringify(obj);
})
), function (obj) {
return JSON.parse(obj);
}
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.