鍍金池/ 問答/HTML/ antd tree defaultExpandAll 問題

antd tree defaultExpandAll 問題

antd tree 設(shè)置 defaultExpandAll為true時(shí),第一次初始化的時(shí)候是默認(rèn)展開的。當(dāng)將樹收攏后關(guān)閉窗口,再次打開窗口時(shí),樹保持收攏狀態(tài)。然后我用expandedKeys來控制需要展開的節(jié)點(diǎn),但是點(diǎn)擊通過expandedKeys設(shè)置的節(jié)點(diǎn)又不能收攏。請(qǐng)問應(yīng)該怎么解決上訴問題呢?謝謝!

 <Tree
    checkable
    onCheck={this.onCheck}
    defaultExpandAll={expandAllState}
    checkedKeys={checkedkey}
    loadData={this.onLoadData}
    expandedKeys={expandedKeys}
  >
   {this.renderTreeNodes(roles)}
  </Tree>
回答
編輯回答
青檸

你設(shè)置了expandedKeys后,Tree組件就變?yōu)槭芸亟M件了。
再次打開窗口時(shí),需要將設(shè)置expandedKeys,將其全部打開。
另外defaultExpandAll屬性只有組件第一個(gè)渲然的時(shí)候,才會(huì)加載,被mount后,該值不再起作用。

2017年4月4日 00:54