laravel - 如何使用 Vuejs 在数组中分配键索引
问题描述
嗨,我有这样的表格:
<tr v-for="(post, index) in posts" v-bind:index="index">
<td>{{ post.rut }}</td>
<td>{{ post.names }} {{ post.father_lastname }} {{ post.mother_lastname }}</td>
<td>
<input type="number" class="form-control" id="exampleInputEmail1" v-model="form.amount[index]" placeholder="Ingresa el monto">
</td>
</tr>
你怎么能看到它有 v-model="form.amount[index]" 但我想做的是:
<input type="number" class="form-control" id="exampleInputEmail1" v-model="form.amount[post.rut]" placeholder="Ingresa el monto">
我的意思是我想分配我自己的索引我的自定义索引我想知道我该怎么做?
我的 vuejs 代码是这样的:
data: function() {
return {
form: {
amount: [],
},
我在 vuejs 中声明了数量数组,你可以在上面看到,但我需要在数组中分配我自己的索引,因为如果我发送数据并在此时检查数组,它是:
0 => value, 1 => value
但我需要这样做
'2714155' => value, '4578745' => value...
我怎样才能做到这一点?谢谢
解决方案
将您的数据声明为对象,然后将值分配给特定键。
data() {
return {
form: {
amount: {},
},
}
}
您可以按原样使用所需的布局。
<input
type="number"
class="form-control"
id="exampleInputEmail1"
v-model="form.amount[post.rut]" <-- here you assign a specific key
placeholder="Ingresa el monto">
推荐阅读
- java - Jython 中的导入问题
- timezone - 目标时区列表/选项
- javascript - 我如何在 Ionic 中使用 Swrve Web SDK
- javascript - Javascript提取值
- java - 将父类扭曲为子类
- python - 如何使用openpyxl在excel图表中只显示一个数据标签?
- android - Android Studio 中插件 Google Cloud Tools Core 中的异常
- angular - onSelectionChange 在 Angular 中被调用两次
- python - python 3 os.remove多个同名文件类型
- vba - 从文档开头跳转到绝对页面