Tree中的api屬性有一個defaultExpandAll
這個屬性只在第一次渲染的時候有效,也就是說用戶刷新頁面後或者在這個頁面操作完這個組件後重新渲染的時候,這個值將不會有效。
解決辦法:
expandedKeys={help.treeIdData}
onExpand={this.onExpand}
使用expandedKeys屬性和onExpand事件進行數據的可控操作
初始化的時候獲取所有的TreeKeysr然後將它設置到expandedKeys屬性上,當用戶操作Tree節點的時候再觸發onExpand更新expandedKeys數據
具體思路參考https://reactjs.org/docs/forms.html 或者 https://github.com/ant-design/ant-design/issues/4145#issuecomment-27058096