ant design vue 嵌套table 的使用以及 expand事件

弹窗原型

需求是在这里插入图片描述
**需求:在点击展开图标(+)时,要根据当前列的 变量编号 查询接口。但是expand事件只会获取当前展开行的数据,所以会造成在展开多行,调用查询接口时,传入了相同的 变量编号 ,从而得到相同的数据列表,参见下图

在这里插入图片描述

  • expand(expanded, record)事件提供了两个参数:
    expanded: 当前行展开 还是 关闭
    record: 当前行数据

  • 展开功能配置提供了 expandRowKeys 属性,可以通过该属性,解决以上问题。每次只需要展开一行,其他行关闭

在这里插入图片描述
在这里插入图片描述

代码

html

<!-- 选择变量弹窗 -->
        <a-modal
          :width="700"
          title="选择变量"
          :visible="visible"
          :confirm-loading="confirmLoading"
          @ok="handleOk('variable')"
          @cancel="handleCancel('variable')"
        >
          <a-table
            @expand="expand"
            :columns="vcolumns"
            :data-source="variableData"
            :pagination="ipagination"
            @change="handleTableChange"
            :expanded-row-keys.sync="expandedRowKeys"
          >
            <a-table
              slot="expandedRowRender"
              :columns="vinnerColumns"
              :data-source="variableInnerData"
              :rowSelection="{onSelect: selectVariable, onSelectAll: selectVariableAll, onChange: onSelectVariable}"
              :pagination="false"
            />
          </a-table>
        </a-modal>
***js***

expand(expanded, record){
      if(expanded){
        let key = this.expandedRowKeys.pop()
        this.expandedRowKeys1 = []
        this.expandedRowKeys1.push(key)
        // 根据选中的数据查询接口
        const data = {
          variablesGroupId: record.id
        }
        variableList(data).then(res => {
          this.variableInnerData = res.result.records
        })
      }
    },
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值