根据匹配对象的某个值,获取数组对象的下标(用于vue表格选中后关闭,再点击回显选中的值)
实现效果:点击图一表格中的单元格,在图二弹窗表格中回显已选信息
html:
<el-table ref="multipleTable" :loading="loading" :data="huiluList" @selection-change="chooseChange" > <el-table-column type="index" width="100" label="序号" ></el-table-column> <el-table-column type="selection"> </el-table-column> <el-table-column property="lineName" label="回路"></el-table-column> </el-table>
js:
showChecked(obj) { obj = obj.split(',') obj.forEach((item, index) => { let indexsw = this.huiluList.findIndex( (el) => el.lineName == obj[index], ) var _this = this setTimeout(function () { _this.$refs.multipleTable.toggleRowSelection( _this.huiluList[indexsw], ) }, 300) }) }, // 查询列表接口 searchLoop(event) { this.showB = true this.loading = true this.idIndex = event.$index let _data = { consNo: event.row.consNo, } getLoop(_data).then((res) => { if (res.code == 0) { this.huiluList = res.data this.loading = false if (event.row.chooseLoop != '') { this.showChecked(event.row.chooseLoop ) } } }) },