我无法在复选框中检索选中的值。如果我将v模型更改为form.permissions [index],它将显示出来,但是如果我保存它,则不会保存。
尝试过这个。
<table class="table table-sm">
<tr v-for="(permission, index) in permissions" :key="permission.id">
<td>{{ permission.name }}</td>
<td><input type="checkbox" class="form-check-input"
:value="permission.id" v-model="form.permissions[index]" checked>
</td>
</tr>
</table>
但是这种情况不会保存/更新数据。
<table class="table table-sm">
<tr v-for="permission in permissions" :key="permission.id">
<td>{{ permission.name }}</td>
<td><input type="checkbox" class="form-check-input"
:value="permission.id" v-model="form.permissions" checked></td>
</tr>
</table>
editRow(data){
this.editmode = true;
this.form.reset();
this.form.clear();
this.form.fill(data);
$('#addNew').modal('show');
},
for the store()
$role = new Role();
$role->name = $request['name'];
$role->ident = $request['ident'];
$role->description = $request['description'];
$role->level = $request['level'];
$role->active = $request['active'];
$role->save();
$role = Role::find($role->id);
$role->permissions()->attach($request['permissions']);
return $role;
for update()
$role = Role::findOrFail($id);
$role->name = $request['name'];
$role->ident = $request['ident'];
$role->description = $request['description'];
$role->level = $request['level'];
$role->active = $request['active'];
$role->permissions()->sync($request['permissions']);
$role->update();
它必须保存和更新数据并检索旧值。
答案 0 :(得分:1)
尝试:checked="form.permissions[index]"
摆脱v-model