The view I have is updated when this.dataSource.data is updated. I want to push() new objects into a deeply nested object dynamically. I currently am feeding an array of viewValue names into a forEach() loop that first finds the index and, with this index, paths it's way down to the desired leaf node.
The issue I'm having is that I need to set this equal to this.dataSource.data, but as I'm digging into the nested object, I'm unable to keep the dot notation path.
I thought I could store the path as a string and convert it with eval() or something, but this seems sloppy, and I haven't gotten that to work either(it usually says that data in this.dataSource.data is undefined, which I'm not sure why. maybe it's a bug with the chrome debugger).
I have a feeling there is a simple answer, but my dumb eyes can't see it. I've looked for similar things on stack overflow, but haven't found anything that really is similar, even though there has to be, as this seems like a seemingly common sounding problem. Maybe, I'm just really bad at google searches.
EDIT: I don't think tracking the path via string and converting the string to an object path is the best approach. this would be a last resort, i think.
Edit2: made '.[results]'
to '["results"]'
removing the .
let pathingObject = this.dataSource.data
let pathingString = 'this.dataSource.data'
if (pathingArray === null) {
this.serviceData.push(data)
console.log(this.serviceData);
this.dataSource.data = this.serviceData
} else {
pathingArray.forEach(element => {
let index = pathingObject.findIndex(p => p.viewValue == element);
pathingObject = pathingObject[index]['results']
pathingString = pathingString + '[' + index + ']' + '["results"]';
});
pathingObject.push(data);
//console.log(eval(pathingString));
// this.dataSource.data = pathingObject;
}