Element-UI樹形結構表格的操作


<el-table :data="tableData" :header-cell-style="{'text-align':'center'}" :cell-style="{'text-align':'center'}"
        style="width: 100%; margin: 15px 0" row-key="id" default-expand-all
        :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
        <el-table-column type="index" label="序號" width="50">
        </el-table-column>
        <el-table-column prop="name" label="字段名" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="xcode" label="字段下標" show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="操作" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tooltip effect="dark" content="添加字段" :enterable="false" placement="top">
              <el-button class="icon-button" type="text" icon="el-icon-circle-plus-outline"
                @click.native.prevent="addHandle(scope.row, scope.$index)">
              </el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
data () {
    return {
        tableData: [
        {
          id: 1,
          name: '字段0'
        }, {
          id: 2,
          name: '字段1'
        }, {
          id: 3,
          name: '字段2',
          children: [{
            id: 31,
            name: '字段2-0'
          }, {
            id: 32,
            name: '字段2-1'
          }]
        }, {
          id: 4,
          name: '字段3'
        }
      ]
    }
  },
  mounted () {
    this.treeTableXcode(this.tableData)
    console.log(this.tableData)
  },
  methods: {
    treeTableXcode (data, xcode) {
    let that = this
    xcode = xcode || ""
      for (var i = 0; i < data.length; i++) {
        var item = data[i]
        item.xcode = xcode + i
        if (item.children && item.children.length > 0) {
          that.treeTableXcode(item.children, item.xcode + "-")
        }
      }
    }
  }

需要對樹形表格某一行進行操作的話,我們可以自己生成一個 xcode 利用它去找對應的上下級關聯關系,拿到對應的數據做處理

 
       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM