1、点击按钮弹出一个dialog同时请求table要展示的数据,dialog中有一个table和分页功能,当打开dialog就给table中的复选框默认选中状态。
我是这样操作的,但是没有任何反应。
//页面上的按钮
<el-button type="primary" **@click="addCcObject"**>添加抄送对象</el-button>
addCcObject(){
this.CCdialog = true;//打开弹出框
this.doCcData()//获取table中要展示的数据。
},
//弹出框
<el-dialog title="添加抄送人" :visible.sync="CCdialog" **@open="showCcDialog"**>
<div style="margin:15px 0">
<el-input v-model="CCinputValue" placeholder="请输入内容" style="width: 200px" clearable></el-input>
<el-button type="primary" @click="ccsearchBtn">搜索</el-button>
</div>
<el-table :data="ccData" ref="ccData" @selection-change="handleSelectionChange" border>
<el-table-column type="selection" width="55">
</el-table-column>
<el-table-column property="caption" label="机构名称"></el-table-column>
</el-table>
<div style="margin:15px 0">
<el-pagination
background
layout="prev, pager, next"
:page-size="pageSize"
:current-page.sync="currentPage"
@current-change="currentChange"
:total="count">
</el-pagination>
</div>
<div slot="footer" class="dialog-footer">
<el-button @click="CCdialog = false">取 消</el-button>
<el-button type="primary" @click="ccOk">确 定</el-button>
</div>
</el-dialog>
//弹出框的回调函数
showCcDialog(){
this.$nextTick(() => {
let selected = this.data_cc//默认要选择复选框的数据
selected.forEach(i => {
this.$refs.ccData.toggleRowSelection(this.ccData.find(d => d.id === i.id), true) // 设置默认选中
})
})
},
showCcDialog(){
this.$nextTick(() => {
let selected = this.data_cc//默认要选择复选框的数据
selected.forEach(i => {
//this.$refs.ccData.toggleRowSelection(this.ccData[2], true) // 设置默认选中
//this.$refs.ccData.toggleRowSelection(this.ccData.find(d => d.id === i.id), true) // 设置默认选中
this.$refs.ccData.toggleRowSelection(this.ccData.find(d => d.id === i.id), true) // 设置默认选中
})
})
},
选中事件不应该放在弹出框的回调函数中,应该放在表格数据请求完成的回调中