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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.