We are currently in the process of designing a form with numerous dependencies that span across different levels of inputs. For example, if parent1.input1 = 'test'
, then child1.input1
should also be 'test'. However, if child1.input2 = 'more test'
, then child1.input3
should equal 'more test'
.
let v = new Vue({
el:'#someEl',
data:{
parentval1:'foo',
parentVal2:'bar',
children:[
{childVal1:'bax', modelAttr:'parentVal1'},
{childVal2:'bix', modelAttr:'childVal1'},
{childVal3:'boom', modelAttr:'childVal2'}
]
},
methods:{
whichModelField(modelAttr){
swith (modelAttr){
case 'parentVal1':
return xx; //should be bound to some data property if modelAttr === 'parentVal1'
case 'childVal1':
return yy; //should be bound to some other data property if modelAttr === 'childVal1'
}
}
}
})
<div>
<p id='parent'>
<input id="1" placeholder="test" v-model="parentVal1"/>
</p>
<p id='child1' v-for="child in children">
<input placeholder="test" v-model="whichModelField(child.modelAttr)"/>
</p>
</div>
I have managed to dynamically bind the v-model
attribute, but I am struggling to achieve true dynamism between the current item's context and the parent data context. In other words, I want to be able to bind to a data property at any level within the data object, and I can't seem to find the correct syntax to accomplish this.