java链表实现列表数据上移下移_table中实现数据上移下移效果

html

由于vue+Element项目中的table,没有开放的上移下移的api,但是能对数据操作,故思路为数组中的一条数据,再重新添加一条数据,办法有点笨,但是好歹也是实现了,望有好的办法的,请留言

:data="tableData"

style="width: 100%"

>

prop="date"

label="日期"

width="180">

prop="name"

label="姓名"

width="180">

prop="address"

label="地址"

:formatter="formatter">

size="mini"

@click="handleUp(scope.$index, scope.row)"

>上移

size="mini"

type="danger"

@click="handleDown(scope.$index, scope.row)">下移

size="mini"

type="danger"

@click="deleteDown(scope.$index, scope.row)">删除

js

data () {

return {

'tableData': [{

date: '2016-05-02',

name: '王小虎',

address: '上海市普陀区金沙江路 1 弄',

id:'1'

}, {

date: '2016-05-04',

name: '王小虎',

address: '上海市普陀区金沙江路 2 弄',

id:'2'

}, {

date: '2016-05-01',

name: '王小虎',

address: '上海市普陀区金沙江路 3 弄',

id:'3'

}, {

date: '2016-05-03',

name: '王小虎',

address: '上海市普陀区金沙江路 4 弄',

id:'4'

}],

'obj':{

'x':1,

'y':2

}

}

},

methods:{

formatter(row, column) {

//console.log('地址格式化',row,column);

return row.address;

},

handleUp(index,row) {

console.log('上移',index,row);

console.log(this.tableData[index]);

if (index > 0) {

let upDate = this.tableData[index - 1]

this.tableData.splice(index - 1, 1);

this.tableData.splice(index,0, upDate);

} else {

alert('已经是第一条,不可上移');

}

},

deleteDown(index,row){

console.log('删除',index,row);

this.tableData.splice(index, 1);

},

handleDown(index,row){

console.log('下移',index,row);

if ((index + 1) === this.tableData.length){

alert('已经是最后一条,不可下移');

} else {

console.log(index);

let downDate = this.tableData[index + 1]

this.tableData.splice(index + 1, 1);

this.tableData.splice(index,0, downDate);

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值