dataobject-parser icon indicating copy to clipboard operation
dataobject-parser copied to clipboard

Merge nested objects together

Open OliverFischer opened this issue 8 years ago • 1 comments

Hi altogether, I have a simple question:

DataObjectParser.prototype.set overwrites property sections complete when adding properties to the resulting model. Is it possible to add a merge mechanism like $obj[$key] = _.merge($obj[$key]||{},$data); in line 35 in dataobject-parser.js? So nested properties can survive in the merge process like in this example:

dataobjParser.set('a',{projectId : 'common',route : 'a',fragment:{key : 'looser', anotherProp : 'I will survive'}})
dataobjParser.set('a', {projectId : 1, route : 'a',fragment:{key : 'winner'}})

I would like to see the the property 'anotherProp' from the first object even when overwriting the second one...

Greetings Olli

OliverFischer avatar May 17 '17 15:05 OliverFischer

Not comfortable with adjusting behavior of set method but we could add a merge method so as to fit your needs.

henrytseng avatar Aug 10 '17 04:08 henrytseng