我正在制作组织结构图,并希望合并此库 https://github.com/unicef/react-org-chart
它适用于他们的演示,但是当我尝试合并到我自己的应用程序中时,我会收到以下错误
错误:index.js:156 Uncaught TypeError:无法读取未定义的属性“树”
我试图控制台日志属性树和树已经定义如下所示。
有谁知道这是图书馆问题还是我没有正确合并?
{id: 1, person: {…}, hasChild: true, hasParent: false, isHighlight: true, …}
children: [{…}]
hasChild: true
hasParent: false
id: 1
isHighlight: true
person:
avatar: "https://s3.amazonaws.com/uifaces/faces/twitter/spbroma/128.jpg"
department: ""
id: 1
name: "Jane Doe"
title: "CEO"
totalReports: 1
__proto__: Object
__proto__: Object
这里是示例代码(ExtOrgChart.jsx)供参考
import React from 'react';
import './App.css';
import OrgChart from '@unicef/react-org-chart';
const tree = {
id: 1,
person: {
id: 1,
avatar: 'https://s3.amazonaws.com/uifaces/faces/twitter/spbroma/128.jpg',
department: '',
name: 'Jane Doe',
title: 'CEO',
totalReports: 1,
},
hasChild: true,
hasParent: false,
isHighlight: true,
children: [
{
id: 2,
person: {
id: 2,
avatar: 'https://s3.amazonaws.com/uifaces/faces/twitter/spbroma/128.jpg',
department: '',
name: 'John Foo',
title: 'CTO',
totalReports: 0,
},
hasChild: false,
hasParent: true,
isHighlight: false,
children: [],
}],
};
function ExtOrgChart() {
console.log(tree);
return (
<div className="App">
<OrgChart tree={tree} />
</div>
);
}
export default ExtOrgChart;
答案 0 :(得分:0)
看起来库本身有一些问题 - https://github.com/unicef/react-org-chart
经过进一步研究和尝试(例如将 D3 设置为特定版本),它仍然不会显示。建议尝试其他库,例如 https://github.com/dabeng/react-orgchart 可能更容易实现。