我有一个 html 表格,应该能够对行和列重新排序。
重新排序行非常漂亮 straight forward但对列重新排序非常困难,因为列的单元格不共享相同的父元素。
<table>
<tr>
<td>Col 1</td>
<td>Col 2</td>
</tr>
<tr>
<td>Col 1</td>
<td>Col 2</td>
</tr>
</table>
如何使用 React 实现列拖动?
最佳答案
您应该在数据和 View 之间添加额外的抽象层 - 其中将使用列索引。例如:
var data : [["a","b","c"],["a2","b2","c2"]];
var columns = [2,1,0];
function getData(row, col) {
return data[row][columns[col]];
}
然后,当您拖动列时 - 您只需更改列 var 内的索引即可。
关于javascript - 通过拖放对表列进行重新排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40729856/