antd Table 上移下移問題

[狀態管理 mobx](https://cn.mobx.js.org/) import { observable ,action, toJS } from 'mobx'; @observable DataSource = []; // 表格列表數據 @observable selectedObj = {}; // 選中的數據 @observable selectedRowKey = ''; // 當前行index // 上移 @action MoveUp(){ // 下面三行代碼意思就相當於冒泡排序 替換ordernum這個值 let x = this.selectedRowKey let orderNum = this.DataSource[x- 1].orderNum; // 點擊當前行index的上一條數據(根據index獲取數據) this.DataSource[x - 1].orderNum = this.DataSource[x].orderNum; // 上移的orderNum 等於 當前點擊數據的orderNum this.DataSource[x].orderNum = orderNum; // 當前數據的orderNum 等於上移orderNum this.selectedObj.orderNum = orderNum; // 使用splice來交換數據 this.DataSource .splice(x- 1, 1, ...this.DataSource .splice((x+ 1) - 1, 1, this.DataSource[x - 1])); } // 下移 @action moveDown(){ // 同理上移 let x = this.selectedRowKey + 1; let y = this.selectedRowKey + 2; let a = this.selectedRowKey; let orderNum = this.DataSource[a + 1].orderNum; this.DataSource[a + 1].orderNum = this.DataSource[a].orderNum; this.DataSource[a].orderNum = orderNum; this.selectedObj.orderNum = orderNum; this.DataSource .splice(x - 1, 1, ...this.DataSource .splice(y - 1, 1, this.DataSource[x - 1])) }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章