I'm still trying to fix this issue. In a different forum I was advised that I should bind checked via a method or computed property that checks if the availableRole matches the item in user.roles at the same index, but I just do not get it to work. No checkbox gets checked. So I have 2 issues here, I might have up to 2 Users returned so I would guess I need index2 for the loop through the User, that should be ok and I could have multiple Roles for each User, but most important right now is to get any Checkbox pre-checked. So in my below example, if I print out this.users[0].roles[0].id then I get "2"
Any advice from anyone? Thank you very much in advance.
<ul>
<li v-for="(availableRole, index) in availableRoles">
<input type="checkbox" v-model="user.roles" :value="availableRole.id" :checked="isChecked(index)">
<label :for="availableRole.id">{{ availableRole.name }}</label>
</li>
</ul>
methods: {
isChecked(index) {
return this.availableRoles[index].id === this.user.roles[index].id
}
}
As I said, my User Object looks like the following:
|JSON||
|---|---|
|0|{…}|
|id|10|
|firstname|Joe|
|lastname|Bloggs|
|username|joeb|
|email|[email protected]|
|no|111|
|parent_no|null|
|roles|[…]|
|0|{…}|
|id|2|
|name|User Admin|
|pivot|{…}|
|model_id|10|
|role_id|2|
|1|{…}|
|id|3|
|name|News Admin|
|pivot|{…}|
|model_id|10|
|role_id|3|
|1|{…}|