【发布时间】:2019-12-03 10:20:58
【问题描述】:
我需要TreeNode 中的antd TreeSelect 来获得null 的值。
但是当它有一个值null 时,它不会在TreeSelect 中显示它
<Tree.TreeNode value={null} title="Head menu"/>
我该如何解决这个问题?
新建->
getSubSelectTree = (topMenuItem: TopMenuItem) => {
if (topMenuItem.subMenu.length > 0) {
let subMenuTreeNodes = [];
for (let x = 0; x < topMenuItem.subMenu.length; x++) {
subMenuTreeNodes.push(this.getSubSelectTree(topMenuItem.subMenu[x]));
}
return <Tree.TreeNode key={topMenuItem.id.toString()} title={topMenuItem.name}
value={topMenuItem.id}>{subMenuTreeNodes}</Tree.TreeNode>
}
return <Tree.TreeNode key={topMenuItem.id.toString()} title={topMenuItem.name} value={topMenuItem.id}
/>;
};
getSelectTree = () => {
if (this.props.menuState.topMenu !== null) {
if (!this.props.menuState.topMenu.loading) {
let treeNodes = [];
for (let x = 0; x < this.props.menuState.topMenu.menuItems.length; x++) {
treeNodes.push(this.getSubSelectTree(this.props.menuState.topMenu.menuItems[x]));
}
return <TreeSelect
placeholder="Selecteer onder welk menu item het moet komen."
allowClear
>
<Tree.TreeNode value={"" + null} title={"Head menu"}/>
{treeNodes}
</TreeSelect>;
}
}
return <></>;
};
这是我现在的代码。我唯一想要的是有一个额外的 TreeNode,它说它是一个主菜单,我在创建时不会有父级。在水下它是无效的
【问题讨论】:
-
你确定
TreeNode有propvalue吗?我不这么认为。 ant.design/components/tree/#TreeNode-props.
标签: reactjs typescript antd