antDesign中Tree组件使用无法渲染问题

新手上路,请多包涵

antDesign 中使用Tree组件,提示渲染错误,但是用的就是官方推荐的方式.

private renderTreeNode = (data: any) => {
    data.map((item: any) => {
      if (item.children) {
        return (
          <TreeNode title={item.positionName} key={item.positionKey} dataRef={item}>
             {this.renderTreeNode(item.children)}
          </TreeNode>
        );
      }
      return <TreeNode title={item.positionName} key={item.positionKey}></TreeNode>;
    });
  }
  • 一方面提示<TreeNode> 没有children属性

antdesign提示没有children属性

  • 在下面渲染的时候也不显示
<Tree
        checkable
        onSelect={this.onSelect}
        onCheck={this.onCheck}
        // checkedKeys={this.state.defaultCheckedKeys}
      >
        {this.renderTreeNode(this.props.authRoleMessage)}
      </Tree>

页面不显示,不知道是哪里的原因,求指教。


数据源:

[
  {
    "positionName": "总经理",
    "positionKey": "101",
    "positionId": "101",
    "isChecked": "N",
    "parentId": "0",
    "children": [
      {
        "positionName": "行政部经理",
        "positionKey": "102",
        "positionId": "102",
        "isChecked": "N",
        "parentId": "101",
        "children": [
          {
            "positionName": "行政员工",
            "positionKey": "991",
            "positionId": "991",
            "isChecked": "Y",
            "parentId": "102"
          }
        ]
      },
      {
        "positionName": "前台经理",
        "positionKey": "93",
        "positionId": "93",
        "isChecked": "N",
        "parentId": "101",
        "children": [
          {
            "positionName": "前台员工",
            "positionKey": "931",
            "positionId": "931",
            "isChecked": "Y",
            "parentId": "93"
          }
        ]
      },
      {
        "positionName": "客户服务部经理",
        "positionKey": "94",
        "positionId": "94",
        "isChecked": "N",
        "parentId": "101"
      },
      {
        "positionName": "人力资源部经理",
        "positionKey": "95",
        "positionId": "95",
        "isChecked": "N",
        "parentId": "101"
      },
      {
        "positionName": "技术部经理",
        "positionKey": "96",
        "positionId": "96",
        "isChecked": "N",
        "parentId": "101"
      },
      {
        "positionName": "运营部经理",
        "positionKey": "97",
        "positionId": "97",
        "isChecked": "N",
        "parentId": "101"
      },
      {
        "positionName": "营销部经理",
        "positionKey": "98",
        "positionId": "98",
        "isChecked": "N",
        "parentId": "101",
        "children": [
          {
            "positionName": "营销部经理",
            "positionKey": "981",
            "positionId": "981",
            "isChecked": "N",
            "parentId": "98"
          }
        ]
      },
      {
        "positionName": "财务部经理",
        "positionKey": "99",
        "positionId": "99",
        "isChecked": "N",
        "parentId": "101"
      }
    ]
  }
]
阅读 4.9k
1 个回答

data.map 需要return 啊

推荐问题