表格增加整行和删除整行

需求: 表格增加整行和删除整行,因为后台数据的特殊性,增加行没有索引。

  addRow() {
      if (this.checkBoxData.length > 1 || this.checkBoxData.length < 1) {
        this.$message.error({
          message: "请选择一行进行添加",
          duration: 2000
        });
      } else {
       //因为增加表格没有索引,所以自己做了个
        let str = Math.floor(Math.random() * 10000).toString();
        let list = {
          idnex: str,
          newIndex: this.checkBoxData[0].purchaseOrderDetailId + str,
          //复制原表格行内容到新增加的表格
         goods: this.checkBoxData[0].goods,
        };
        this.tableData.push(list);
      }
    },    

删除增加的行

  //删除批号
    delRow() {
      if (this.checkBoxData.length < 1) {
        this.$message.error({
          message: "请至少选择一行进行删除",
          duration: 2000
        });
        return;
      }
      this.checkBoxData.forEach(e => {
        this.tableData.splice(
          this.tableData.findIndex(item => item.newIndex == e.newIndex),
          1
        );
      });
    },

猜你喜欢

转载自www.cnblogs.com/0520euv/p/12183202.html
今日推荐