vue.js - vuejs how to check if key/ID exist in the array -


i have array of roles lists roles available. each user assigned 1 or more roles, named user_roles.

i listing roles checkboxes, default marked unchecked. when select user, want able check if role id in list matches id user_roles array.

in php/html can achieve using

<?=in_array($user_roles, $role->id) ? 'checked' : '' ?> 

how can achieve same thing in vuejs?

i'm trying same idea using below example:

<input type="checkbox" name="role[]" :value="role.id" :id="'role' + role.id" :checked="in_array(user_roles, role.id)" /> 

use array's indexof method:

:checked="user_roles.indexof(role.id) >= 0" 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -