change_faculty(){ selectstaff({facultyId:this.form.fId}).then((resopnse) => { this.staffNumber = resopnse.data; }) }, change_selsect(){ // console.log("jinlai") for(const staffss of this.staffNumber){ // console.log(staffss.staffNumber+"aaa") if(staffss.staffNumber==this.form.firstStaffNumber){ this.form.firstStaffName = staffss.staffName } } },修改代码实现三个下拉框的联动
时间: 2024-02-21 16:02:07 浏览: 74
以下是修改后的代码实现三个下拉框的联动:
```
change_faculty() {
selectstaff({facultyId:this.form.fId}).then((response) => {
this.staffNumber = response.data;
this.form.firstStaffNumber = '';
this.form.secondStaffNumber = '';
this.form.thirdStaffNumber = '';
this.change_selsect();
})
},
change_selsect() {
let firstStaffName = '';
let secondStaffName = '';
let thirdStaffName = '';
for (const staff of this.staffNumber) {
if (staff.staffNumber === this.form.firstStaffNumber) {
firstStaffName = staff.staffName;
}
if (staff.staffNumber === this.form.secondStaffNumber) {
secondStaffName = staff.staffName;
}
if (staff.staffNumber === this.form.thirdStaffNumber) {
thirdStaffName = staff.staffName;
}
}
this.form.firstStaffName = firstStaffName;
this.form.secondStaffName = secondStaffName;
this.form.thirdStaffName = thirdStaffName;
}
```
其中,`change_faculty` 函数会在选择学院的下拉框变化时被调用,用来获取该学院的所有教师信息,并将 `this.staffNumber` 数组中存储所有教师信息。
`change_selsect` 函数会在选择教师的下拉框变化时被调用,用来根据选择的教师编号更新教师姓名,并将其赋值到 `this.form` 对象中对应的属性上。
需要注意的是,当选择学院的下拉框变化时,应该将 `this.form.firstStaffNumber`、`this.form.secondStaffNumber`、`this.form.thirdStaffNumber` 这三个属性的值都清空,以免出现未选择教师时教师姓名还保留着上一次选择的教师姓名的情况。
阅读全文