当treeselect具有空值时,将不会显示

时间:2019-12-03 10:20:58

标签: reactjs typescript antd

我需要TreeNode TreeSelect中的antd才能具有值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,上面说它是一个主菜单,创建时我不会有一个父级。而在水下它为空

1 个答案:

答案 0 :(得分:0)

要仅显示标题,您可以删除值并按如下所示使用它

 <Tree>
    <Tree.TreeNode title={"Head Menu"}></Tree.TreeNode>
 </Tree>