我正在将 Ant Design 用于 React Js UI。正在使用 Tree 组件显示在列表中。我还有 2 个按钮来展开和折叠树列表。我使用defaultExpandAllprops来管理它。在展开和折叠按钮上单击我将布尔值分别设置为 true 和 false。按钮它不会在按钮点击时展开。如果我最初将 True 设置为该标志状态,则它可以工作。是否有任何工作。
我有 2 个组件。(展开和折叠按钮在父组件中)
**Parent Component**
setExpandOrCollapse(value) {
this.setState({ expandOrCollapse: value });
}
<HeaderRow>
<Button onClick={() => this.setExpandOrCollapse(true)}>Expand All</Button>
<Button onClick={() => this.setExpandOrCollapse(false)}>Collapse All</Button>
</HeaderRow>
<Card>
{ItemTree && (ItemTree.length > 0) ? (
<ItemTree
dataSource={ItemTree}
expandOrCollapse={expandOrCollapse}
/>
) : null }
</Card>
**Child Component**
<Tree
draggable={isDraggable}
defaultExpandAll={expandOrCollapse}
>
{loopitemNodes(dataSource)}
</Tree>
数据源是从 Redux api 调用中获得的。
有没有解决办法。