【发布时间】:2016-10-19 18:47:36
【问题描述】:
我有一个复选框列表,它是使用由 id 和名称组成的 for 循环生成的:
Data:
yards[{id:1,name:'test'}] etc
HTML:
<ul class="checkbox-list">
<template v-for="(yard, index) in yards">
<li>
<input type="checkbox"
v-bind:id="'yardlist_'+yard.name"
v-bind:value="yard.id"
v-model="newSchedule.yards.id">
<label v-bind:for="'yardlist_'+yard.name">{{ yard.name }}</label>
</li>
<li>
<input type="text"
class="form-control"
placeholder="Yard notes..."
v-model="newSchedule.yards.notes">
</li>
</template>
</ul>
我想将选中的复选框与 id 和 notes 字段一起保存在一个数组中:
newSchedule: {
due_at: '',
notes: '',
users: [],
yards: [{id:'',notes:'']
}
我尝试使用码数组中的索引:newSchedule.yards[index].notes 但收到以下错误 "TypeError: undefined is not an object (evalating 'newSchedule.yards[index].id ')"
有什么想法可以实现吗?
** 更新 ** 这是我想要实现的基本小提琴: https://jsfiddle.net/j7mxe5p2/13/
【问题讨论】:
标签: javascript arrays vue.js