Reputation: 28674
I want to get underlying data, of selected node in antd tree.
This is sample tree data (just one node):
let treeData =[{title: "0-0",
key: "0-0",
children: []}];
Tree has onSelect with such signature:
onSelect = (selectedKeys, info) => {
};
info.node.getNodeState()
gives me such result when I select node:
You can see the title
is a react element. Instead I wanted just the underlying value of title
element, that is: "0-0"
.
Is there no way to access the selected nodes underlying data?
Upvotes: 1
Views: 4350
Reputation: 1760
You can use
info.selectedNodes[0].props
to access the nodes data. Or if you pass the data in as prop like -
<TreeNode title={item.title} key={item.key} dataRef={item}>
{this.renderTreeNodes(item.children)}
</TreeNode>
then you can also get the data in info.selectedNodes[0].props.dataRef
Upvotes: 2