weixin_58412143 2022-11-24 13:41 采纳率: 91.6%
浏览 7
已结题

基于vue2+element,#嵌套#多选表格的问题,如何解决?

情景:基于vue2+element,制作的嵌套多选表格,共三层,二层没有多选框只是有内容要展示,所以只有一级和三级表格互相联动
问题:选中子级表格可以联动到一级表格,但是一级勾选后却不能全部选中第三级的数据,只是部分被勾选了,但是控制台可以打印到全部的数据,只是样式没有出来,
代码如下


        <el-table :data="paramsList" :show-header="false" ref="tableF" @select="handleSelectionChange"
           :row-key="getRowKey">
                        <el-table-column width="55" type="selection" ></el-table-column>
                        <el-table-column>
                            <template slot-scope="scope">

                             <el-table :data="scope.row.goodsList" >
                                        <el-table-column align="center">
                                            <template slot-scope="scopeSon">

                                                  <el-table :data="scopeSon.row.spuList" :show-header="false"
                                            :ref="'tableChildSon' + scopeSon.$index" @select="handleSelectionChange3    :row-key="spuList.goodsId">
                                                            <el-table-column width="55" type="selection"></el-table-column>
                                                              <template slot-scope="scopeSons">
                                                                  

JS:

  //一级表格勾选
      handleSelectionChange(selection, row) {
        //判断一级表格是否选中  选中--true  未选中--0
        let isCheck = selection.length && selection.indexOf(row) !== -1;
        //循环整个表数据--找到勾选的 index
        this.paramsList.forEach((item, index) => {
          if (item.id == row.id) {
            let tempList = row.goodsList;
            this.spuList = []
            tempList.forEach((item1, index1) => {
              item1.spuList.forEach((items, indexs) => {
                this.spuList.push(items)
              })
            })
            //以防3级列表没有数据
            if (this.spuList) {
              //循环本次勾选的数据
              this.spuList.forEach((selectionItem, index) => {
                console.log('selectionItem', selectionItem, isCheck);
                this.$nextTick(function() {
                  this.$refs["tableChildSon" + [index]]
                    .toggleRowSelection(
                      selectionItem,
                      isCheck
                    );
                });
              });
              // 联动外部全选框
              if (this.shoped > this.spuList.length) {
                this.allType = true
              } else {
                this.allType = false
              }
            } else {
              this.$refs[`tableChildSon${index}`].clearSelection();
            }
          }
        })
      },
      //三级表格勾选
      handleSelectionChange3(selection, row) {
        let isCheck = selection.length && selection.indexOf(row) !== -1;
        //判断3级列表是否取消勾选(无数据)
        if (isCheck === 0) {
          isCheck = false
        } else {
          isCheck = true
        }
        this.paramsList.map(item => {
          item.goodsList.forEach((itemson, index) => {
            if (itemson.id == row.goodsId && itemson.shopId == item.id) {
              this.$refs.tableF.toggleRowSelection(item, isCheck);
            }
          });
        })
      },
    
  • 写回答

2条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-11-24 16:22
    关注
    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 5月14日
  • 创建了问题 11月24日

悬赏问题

  • ¥15 数据量少可以用MK趋势分析吗
  • ¥15 使用VH6501干扰RTR位,CANoe上显示的错误帧不足32个就进入bus off快慢恢复,为什么?
  • ¥15 大智慧怎么编写一个选股程序
  • ¥100 python 调用 cgps 命令获取 实时位置信息
  • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?
  • ¥15 C语言使用vscode编码错误
  • ¥15 用KSV5转成本时,如何不生成那笔中间凭证
  • ¥20 ensp怎么配置让PC1和PC2通讯上
  • ¥50 有没有适合匹配类似图中的运动规律的图像处理算法
  • ¥15 dnat基础问题,本机发出,别人返回的包,不能命中