• vue中循环table表格数据,可编辑的列表(新增、删除、修改)


    原文链接:https://blog.csdn.net/qq_24441205/article/details/126142669

    1.如何循环如下图table表格数据(注:emerResponseDetail为整个列表定义的数据对象)


    因"作业人员"为数组workPersonList,所以使用template 先循环该数组,再循环该数组里面的字段

    <table>
    <tr><th>姓名</th><th>抢修队</th><th>操作<el-button icon="el-icon-plus" class="greenbg fr" type="mini" @click="addWorkPerson" :disabled="isDisabled"></el-button></th></tr>
    <template v-for="(item1,index) in emerResponseDetail.workPersonList">
    <template v-if="index == 'rows'" v-for="item2 in item1">
    <tr><td>{{item2.userName}}</td><td>{{item2.teamName}}</td></tr>
    </template>
    </template>
    </table>
    1
    2
    3
    4
    5
    6
    7
    8
    2.怎么让table表格中获取到的数据可编辑、新增、删除


    1)把获取到的数据{{item2.userName}}改成input输入框或select下拉框,并进行双向数据绑定

    //到达现场时间、抢修队到达用时可编辑的写法
    <tr>
    <td>到达现场时间</td>
    <td>
    <el-date-picker
    :disabled="isDisabled"
    v-model="emerResponseDetail.teamFirstArriveTime"
    type="datetime"
    placeholder="选择日期时间"
    value-format="yyyy-MM-dd HH:mm:ss"
    default-time="12:00:00">
    </el-date-picker>
    </td>
    <td>抢修队到达用时(分)</td><td><el-input clearable :disabled="isDisabled" v-model="emerResponseDetail.teamArriveUseTime" style=" auto;"></el-input></td>
    </tr>
    //作业人员table列表
    <table>
    <tr><th>姓名</th><th>抢修队</th><th>操作<el-button icon="el-icon-plus" class="greenbg fr" type="mini" @click="addWorkPerson" :disabled="isDisabled"></el-button></th></tr>
    <template v-for="(item1,index) in emerResponseDetail.workPersonList">
    <template v-if="index == 'rows'" v-for="item2 in item1">
    <!--<tr><td>{{item2.userName}}</td><td>{{item2.teamName}}</td></tr>-->
    <tr>
    <td><el-input clearable :disabled="isDisabled" v-model="item2.userName" style=" auto;"></el-input></td>
    <td>
    <el-select v-model="item2.teamId" clearable placeholder="" style=" 100%;" :disabled="isDisabled">
    <el-option
    v-for="item in contingencyTeam"
    :key="item.teamId"
    :label="item.teamName"
    :value="item.teamId">
    </el-option>
    </el-select>
    </td>
    <td>
    <el-button type="text" size="small" @click="delUserName(item2)" :disabled="isDisabled" class="orange">删除</el-button>
    </td>
    </tr>
    </template>
    </template>
    </table>
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    2.新增、删除方法

    //新增作业人员
    addWorkPerson(){
    //为新增作业人员定义一个addWorkPersonForm 对象进行数据保存,并追加到列表emerResponseDetail里的workPersonList数组中
    let addWorkPersonForm = {
    userName:'',
    teamId:'',
    teamName:''
    };
    this.emerResponseDetail.workPersonList.rows.push(addWorkPersonForm)
    },
    //删除作业人员
    delUserName(item){
    var index = this.emerResponseDetail.workPersonList.rows.indexOf(item)
    if (index !== -1) {
    this.emerResponseDetail.workPersonList.rows.splice(index, 1)
    }
    },
    //确定按钮
    saveUpdate(){
    enterButton(this.emerResponseDetail).then(res =>{
    this.getEmergencyResponseList()
    this.$message.success("修改成功!")
    })
    this.isShowDialog = false
    this.isDisabled= true;
    this.isBtnShow = false;
    },

  • 相关阅读:
    linux查看端口号监听状态
    linux / centos 安装SQL Server 2017 设置默认语言与排序规则Chinese_PRC_CI_AS
    centos 生产环境部署 asp.net core
    shell参数处理模板
    搜狗语料库数据整编
    Call From master/192.168.128.135 to master:8485 failed on connection exception: java.net.ConnectException: Connection refused
    spark-shell启动报错:Yarn application has already ended! It might have been killed or unable to launch application master
    webmagic爬取博客园所有文章
    jdbc链接hive报错:java.lang.ClassNotFoundException: org.apache.thrift.transport.TTransport
    NotePad++ 正则表达式替换 高级用法 [转]
  • 原文地址:https://www.cnblogs.com/fswhq/p/16706511.html
Copyright © 2020-2023  润新知