天天看點

table表格中資料點選,資料上移,資料下移功能

其實就是兩條資料互換位置,上移就是目前條跟上一條互換位置,下移就是目前條和下一條互換位置。

// table資料上移
export function moveUpTable(tableData, index) {
  if (index === 0) {
    // 資料已經置頂
  } else {
    tableData.splice(index - 1, 1, ...tableData.splice(index, 1, tableData[index - 1]))
  }
}
// table資料下移
export function moveDownTable(tableData, index) {
  if (index === tableData.length - 1) {
    // 資料已經置底
  } else {
    tableData.splice(index + 1, 1, ...tableData.splice(index, 1, tableData[index + 1]))
  }
}
           

tableData是表格的資料,index為目前條索引。

繼續閱讀