0👍
This should work
<template>
<div>
<div id="app">
<div v-for="role in roles" class="role-row">
<label>{{role.role_name}}</label>
<hr>
<div v-for="(perm,index) in role.perms">
<input type="checkbox" @change="getRole(role,index)" :value="perm" v-model="checked_roles"> {{ perm.perm_name }}
</div>
</div>
<p>Selected roles and perms</p>
{{checked_roles}}
</div>
</div>
data: {
checked_roles: [],
checked_roles_with_role_name: [],
roles: [
{
"role_id" : 1,
"role_name" : 'Administrator',
"perms" : [
{
"perm_id" : 1,
"perm_name" : 'Create'
},
{
"perm_id" : 2,
'perm_name' : 'Update'
},
{
"perm_id" : 3,
'perm_name' : 'Delete'
}
]
},
{
"role_id" : 2,
"role_name" : 'Moderator',
"perms" : [
{
"perm_id" : 1,
"perm_name" : 'Create'
},
{
"perm_id" : 2,
'perm_name' : 'Update'
},
{
"perm_id" : 3,
'perm_name' : 'Delete'
}
]
}
]
},
methods:{
getRole(role,index){
this.checked_roles_with_role_name={checked_roles:this.checked_roles,role_name:role.role_name}
}
}
SO “checked_roles_with_role_name” data property should hold selected role and their role names
- [Vuejs]-How can i change date format in vue js template
- [Vuejs]-Trying to create an embed able Vue Component bundled with Laravel Mix
0👍
Best technique for syncing object from child to direct parent is to use .sync modifier. More info here.
- [Vuejs]-Dropzone.js autoProcessQueue not working within Vue component
- [Vuejs]-How to add and run Three Js old code to Vue page component
Source:stackexchange.com