So I have a nested object stored in my Pinia store. It is something like this.
templateObj = {
contents: [
{
'foo': 'AAA'
'zoo': {
'tee': {
'wee': "",
'alt': "",
}
}
},
{
'foo': 'BBB'
'moo': {
'bee': {
'poo': {
'chi': "",
'rye': "",
}
}
}
},
]
}
I have a variable that holds the information what part of the object I should be updating.
const mapStr = 'zoo.tee.wee'
My problem now is how can I navigate to that part and actually fill in the data.
My current solution below, was able to navigate to the part of the object, but its not updating its value.
In the actions of my Pinia store definition, I have this method.
actions: {
setValueToTargetTemplateModule () {
const srcMapStrArr = mapStr?.split('.')
if (srcMapStrArr && moduleId !== undefined) { //moduleId is a state variable also that holds the index number of which content should be updated
let templateProp = this.templateObj?.contents[moduleId]
for (const key of srcMapStrArr) {
templateProp = templateProp[key]
}
templateProp = "Updated Value"
}
}
},