I have a VueJS data store like this...
nodes: {
id: '001',
name: 'name1',
text: 'test1'
children: [
{
id: '002',
name: 'name2',
text: 'test2'
},
{
id: '003',
name: 'name3',
text: 'test3'
children: [
{
id: '0002',
name: 'name02',
text: 'test02',
children: [
{
id: '0002',
name: 'name02',
text: 'test02'
}
]
}
]
},
{
id: '004',
name: 'name4',
text: 'test4'
}
]
}
Note: children's level (deep) is UNLIMITED
I need to select each by its id and add/update its sibling value.
Example: "Select id: 003 and add a text2: hello '
nodes: {
id: '001',
name: 'name1',
text: 'test1'
children: [
{
id: '002',
name: 'name2',
text: 'test2'
},
{
id: '003',
name: 'name3',
text: 'test3',
text2: 'hello'
},
{
id: '004',
name: 'name4',
text: 'test4'
}
]
}
I managed to do the add/update part using a method
which call:
this.$set(this.nodes, 'text2', 'hello')
I'm stuck at selecting by id part. Can anyone figure out how to do so?
PS: I'm new to VueJS.