相关文章推荐
深情的围巾  ·  .NET(C#) Dapper ...·  1 年前    · 
飘逸的人字拖  ·  insert into table ...·  1 年前    · 
想表白的打火机  ·  Parse GeoJSON file ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

The component: https://ant.design/components/tree-select/ There is no example with the loadData option.

async getChildren(node) {
    console.log(node);
    let r = $.get("/tree", {id: node.value})
    console.log(await r);  // request works
    return r;

With this code I just see the tree loading and nothing happens. Not an error, but the child nodes are not appended to the tree.

If I don't return a Promise, I get a huge error and a blank page.

return new Promise((resolve) => { setTimeout(() => { const treeData = [...this.state.treeData]; getNewTreeData(treeData, treeNode.props.eventKey, generateTreeNodes(treeNode), 2); this.setState({ treeData }); resolve(); }, 500);

You can find it here with more in-deep examples

To make it clearer:

  • TreeData is an Array of TreeNode source
  • antd tree select uses rc-tree because antd is built on top of rc-components you can see the source
  • For lazy load you need to manipulate the treeNode, what above snippet does is: everytime loaded new data it will be a treeNode object, and will call the onLoadData() callback where you provide the code what to do with that node. (the sample just append to the state's treeData variable]
  • Is that the same component? It doesn't look like ant design. And, While this example works, it creates TreeNode component, and I'm trying to use treeData alone – user3599803 Sep 7, 2018 at 14:34 Ant design is built on top of rc-components.react-component.github.io/badgeboard. they are mantained by the same guys. antd is just a themed version of rc-component with some trimmed props – Yichz Sep 7, 2018 at 14:54 for lazyLoad you need to manipulate the treeNode, yourself, treeData is just an array of treeNode github.com/ant-design/ant-design/blob/master/components/… – Yichz Sep 7, 2018 at 14:57 And how the rendering looks (JSX)? Do I have to use async recursive rendering to create TreeNodes? Like here: codesandbox.io/s/5ym6rw3yn4 . As you can see renderTreeNodes() is a recursive function. I don't like this way, I prefer to add nodes to treeData – user3599803 Sep 7, 2018 at 15:10

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.