Element-ui表格选中回显
先瞄一下,是不是你要的效果

然后,废话不多说,直接上代码啦
<template>
<div class>
<div class="projectData">
<el-table :data="tableData2" ref="multipleTable" :show-header="false" :border="false" style="width: 100%" @selection-change="handleSelectionChange">
<el-table-column type="selection" :reserve-selection="true" width="55"></el-table-column>
<el-table-column prop="spaceName" width="180"></el-table-column>
<el-table-column>
<template slot-scope="scope" v-if="scope.row.id==1||scope.row.id==3||scope.row.id==4">
<el-input
v-model="scope.row.spacePrice"
class="el-input_inner"
size="medium"
clearable
></el-input>
{{scope.row.spaceUnit}}
</template>
</el-table-column>
</el-table>
</div>
<el-button type="primary" @click="submitForm">确定</el-button>
</div>
</template> <script>
export default {
data() {
return {
tableData2: [],
multipleSelection: [],
listData:[],
};
},
methods: {
handleSelectionChange(val) {
this.multipleSelection = val;
for (var i = 0; i < this.multipleSelection.length; i++) {
this.multipleSelection[i].containSpace = 1;
}
},
// 初始化数据
projectManage(){
this.$axios.get("/clapi/materiel/mealSpaceRela/queryProjectManage?mealId="+this.message.id)
.then((response) => {
if(response.data.status.code == 200){
this.tableData2 = response.data.result;
this.listData = response.data.result
for ( let i = 0 ; i < this.listData.length ; i++ ){
if(this.listData[i].containSpace == 1){
//这是默认选中上的
this.$refs.multipleTable.toggleRowSelection(this.tableData2[i],true);
}
}
}
})
.catch(error => {
console.log(error);
});
},
// 保存
submitForm() {
// 数组为空的话,状态为0,输入框为0
if(this.multipleSelection.length == 0){
for (var i = 0; i < this.tableData2.length; i++) {
this.tableData2[i].containSpace = 0;
this.tableData2[i].spacePrice = 0;
}
this.$axios.post("/clapi/materiel/mealSpaceRela/editProjectManage",this.tableData2)
.then((response) => {
this.$message({
type: "success",
message: "保存成功!"
});
})
.catch((error) =>{
console.log(error);
});
}else{
//已选数据,其他输入的值为0
for(var n=0;n<this.multipleSelection.length;n++){
// 如果选中的数据为空默认为0
if(this.multipleSelection[n].spacePrice=='')this.multipleSelection[n].spacePrice=0;
}
this.$axios.post("/clapi/materiel/mealSpaceRela/editProjectManage",this.multipleSelection)
.then((response) => {
this.$message({
type: "success",
message: "保存成功!"
});
})
.catch((error) =>{
console.log(error);
});
} },
},
created() {
this.projectManage(); }
};
</script> <style scoped>
.projectData >>> .el-input__inner {
text-align: center;
} .projectData >>> .el-table--enable-row-hover .el-table__body tr:hover > td {
background: #fff!important;
} .projectData tr {
height: 60px !important;
}
.projectData {
margin-left: 80px;
}
.favour_checkbox {
height: 60px;
display: block;
} table,table th,table tr td {
border:1px solid red;
} .el-input_inner,
.el-select {
text-align: center;
width: 100px;
} </style>
若有不明白请加群号:复制 695182980 ,也可扫码,希望能帮助到大家。

Element-ui表格选中回显的更多相关文章
- element ui 表格提交时获取所有选中的checkbox的数据
<el-table ref="multipleTable" :data="appList" @selection-change="changeF ...
- ui.datepicker的回显问题
应用场景: 页面上有一些现有的输入框,需要调用日期插件,同时还要clone一份,动态添加到页面中,动态生成的输入框在调用datepicker的时候,click事件有效,但是选择的时间无法回显到对应的输 ...
- Element UI表格组件技巧:如何简洁实现跨页勾选、跨页统计功能
业务场景 在使用Element UI的Table组件时,常常面对这样的业务需求: 表格数据的每一项都要提供勾选框,当切换分页时,能够记忆所有页面勾选的数据,以实现批量提交不同页面勾选数据的功能.并且, ...
- vue element select多选回显
我们经常在使用 Element组件里面的 select多选 场景:添加账号的时候需要选择可见分公司(分公司为多选),添加成功之后可以编辑,需要回显添加时所提交的分公司 代码如下: 多选框: data( ...
- vue + element ui 表格自定义表头,提供线上demo
前言:工作中用到 vue+element ui 的前端框架,需要使用自定义表头,需要使用 re.转载请注明出处:https://www.cnblogs.com/yuxiaole/p/9710826.h ...
- 封装一个优雅的element ui表格组件
现在做后台系统用vue + elementUI 的越来越多,那element ui的 el-table 组件肯定也离不开.虽然element ui的table组件很好.但是表格和分页是分离的.每次写表 ...
- html option选中 回显 取值
1.html <select class="form-control" id="sex"> <option value="-1&qu ...
- element ui表格常用功能如:导出 新增 删除 多选 跨页多选 固定表头 多级表头 合并行列 等常见需求
<template> <div class="table-cooperte"> <el-table :data="tableData&quo ...
- vue2.0+Element UI 表格前端分页和后端分页
之前写过一篇博客,当时对element ui框架还不太了解,分页组件用 html + css 自己写的,比较麻烦,而且只提到了后端分页 (见 https://www.cnblogs.com/zdd20 ...
随机推荐
- 运行main方法找不到类
http://blog.csdn.net/chenleixing/article/details/44816629
- echarts 图的点击事件(含:点击重复触发的问题及其解决方法)
今天用echarts的时候发现一个问题 鼠标指向不同地市触发一个事件展示该地区趋势图 但是但是后台中不管我第几次鼠标指向都会触发两次指向事件 现在贴出解决办法: 问题完美解决.但是为什么会调用两次, ...
- Linux中检查本地系统上的开放端口列表的方法
在 Linux 中很少有用于此目的的实用程序.然而,我提供了四个最重要的 Linux 命令来检查这一点. 你可以使用以下四个命令来完成这个工作.这些命令是非常出名的并被 Linux 管理员广泛使用.n ...
- toggle,hasClass
toggle 但当toggle(),不带参数时,与show()和hide()的作用一样,切换元素的可见状态,如果元素是可见的,则切换为隐藏状态;如果元素是隐藏的则切换为可见状态,此时括号内可添加()毫 ...
- 使用特性将数据库返回的datatable转换成对象列表
public class ColumnMapAttribute : Attribute { private readonly string _name; public ColumnMapAttribu ...
- lnmp一键安装包安装失败,或者安装下载缓慢的解决办法
使用阿里云内网安装模块 阿里云外网: ftp://soft6.vpser.net/ 阿里云云内网:ftp://10.163.196.147 修改lnmp.conf 文件 目前可用的国内LNMP ful ...
- Spring AOP 简介
Spring AOP 简介 如果说 IoC 是 Spring 的核心,那么面向切面编程就是 Spring 最为重要的功能之一了,在数据库事务中切面编程被广泛使用. AOP 即 Aspect Orien ...
- ElasticSearch(十一)Elasticsearch清空指定Index/Type数据
POST /index_name/type_name/_delete_by_query?conflicts=proceed { "query": { "match_all ...
- spring-data-jpa中save不触发数据库insert语句的问题
最近学习spring mvc,用到jpa简化DAO层代码,发现save死活不触发SQL语句,找了好久才解决这个问题,实在是坑.. <!-- 关键是这个bean,一定要设置正确才行 --> ...
- vue scrolle在tab 中使用
1. 使用npm 安装 npm i vue-scroller -S 地址: https://github.com/wangdahoo/vue-scroller2. 引入 main.js: import ...