【发布时间】:2019-11-29 04:13:36
【问题描述】:
我有一个使用 vuex getter 检索到的来自 vuex 状态的申请人列表。从前端,我将他们各自的结果记录为一个数组并提交他们的结果。但我无法将申请者 ID 分配给 v-model。
我尝试过使用数组和数组对象但不起作用。 我尝试循环创建页面上的申请者列表并将其分配给Vue数据中声明的数组数据。
模板代码
<template>
<table style="margin-left:10%;">
<tr>
<th>#</th>
<th>Full Name</th>
<th>Result</th>
</tr>
<tr
v-for="(applicant, key) in getApplicants"
:key="applicant.applicant_id"
>
<td>{{ key + 1 }}</td>
<td>
{{ applicant.first_name }} {{ applicant.middle_name }}
{{ applicant.last_name }}
<b-form-input v-model="record.applicant_id[key]"></b-form-input>
</td>
<td>
<b-form-input v-model="record.exam_result[key]"></b-form-input>
</td>
</tr>
</table>
<template>
脚本代码
data() {
return {
update: false,
record: {
job_vacancy_id: null,
exam_type_id: null,
applicant_id: [],
exam_result: []
}
};
methods:{
save() {
var object = {
job_vacancy_id: this.record.job_vacancy_id,
manpower_requisition_id: this.manpower_requisition_id,
applicants_id: this.applicants_id,
exam_result: this.record.exam_result
};
console.log(object);
},
populate() {
let appliacnts = this.getApplicants;
for (var i = 0; i <= appliacnts.length; i++) {
this.record.applicant_id = this.appliacnts.applicant_id[i];
}
}
},
created() {
this.populate();
}
【问题讨论】:
标签: javascript arrays object vue.js