我有一种情况,当用户被路由到此页面时,我有一个最初是从服务器数据填充的表。我也在使用React Router。
构造基本表后,每一行都有一个“展开”按钮。当用户单击“扩展”按钮时,这些按钮将切换为“折叠”,并从服务器获取数据并将行添加到表中的特定位置。
具体位置由我表中的一些data-attr-id信息确定。
从本质上讲,这就是您所说的“树表”。
我想我已经意识到一些事情:
(1) I need to make a TreeTableRow component
(2) I need to make a TreeTable component that holds an array of TreeTableRows
(3) Whenever someone clicks on a <Button>, I need to be able to capture the TreeTableRow and then TreeTable and then change the state of the TreeTable.
(4) When I update the TreeTable I will have to write logic to scan the TreeTableRows to find the right row to put the new TreeTableRows below.
(5) When someone clicks a <Button> again, I need to remove the rows that were added specifically from this button click.
我有点迷路了。如果有人可以向我展示一个简单的TreeTableRow和TreeTable以及某种类型的关系,那么我显然可以执行逻辑来找出将行放置在何处,等等。但是基本上,表行上有两个属性(parentId和id)