Reputation: 2060
I am new with loash and need help on this.
i have 2 objects:
{
"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. 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 .
Upvotes: 1
Views: 752
Reputation: 2060
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);
}
);
Upvotes: 1