student
student

Reputation: 35

how to add element as title in tree for reactjs

Hi I am using this ( http://react-component.github.io/tree/examples/dynamic.html ) example to create a dynamic tree. I am new to reactJS. In the Api description it is mentioned that we can use string/element as title. In this example string is used as treenode, I want to use element as a treenode because i want to display more information with the title name. Can anyone help me out where to start with or where to add element code so it will display for all the parent and child node.

Thanks in advance.

Upvotes: 2

Views: 363

Answers (1)

Mohit
Mohit

Reputation: 1215

In the render() function in place of return <TreeNode title={item.name} key={item.key}>{loop(item.children)}</TreeNode>; You can use <TreeNode className="data-loop" title={myElement(item.name,item.address,item.age)} key={item.key}>{loop(item.children)}</TreeNode> and define your 'myElement' like

var myElement =(name,address,age) =>{
      return (
        <span>
          Name: {name} <br/>
          address:{address} <br/>
          Age: {age}
          </span>

        )
    }

Upvotes: 2

Related Questions