【问题标题】:Error while using orgchart: Cannot read property '_aZ' of null使用 orgchart 时出错:无法读取 null 的属性“_aZ”
【发布时间】:2015-08-25 15:02:27
【问题描述】:

我正在尝试使用http://www.getorgchart.com 上的这个组织结构图库

很少有节点可以完美运行,但是,当我尝试加载整个组织(大约 1100 个具有多个嵌套级别的主题)时,我收到以下控制台错误:

未捕获的类型错误:无法读取 null 的属性“_aZ”

并且无法显示图表。

我们将不胜感激。 谢谢!

【问题讨论】:

  • 你能告诉我们你的代码吗?

标签: javascript jquery html orgchart


【解决方案1】:

经过一番研究,我已经解决了这个问题。

问题是您首先需要父母订购的数据源(文档中没有说明);让我们看看在客户端初始化在线演示中的这个例子:


    $('#people').getOrgChart({
    theme: "vivian",
    primaryColumns: ["name", "title", "phone", "mail", "postcode"],
    imageColumn: "image",
    gridView: true,
    dataSource:[            
        { id: 1, parentId: null, name: "Elizabeth Horton", title: "Founder", phone: "(03) 9252 4642" , image: "images/f-46.jpg", mail:"elizabeth.horton@live.com", postcode: "PH2 2SR" },
        { id: 2, parentId: 1, name: "Emily Horton", title: "Fork lift operator", phone: "(08) 9015 4407", image: "images/f-45.jpg", mail:"emily.horton@live.com", postcode: "BA5 0AP"  },
        { id: 3, parentId: 1, name: "Robert Nolan", title: "Blockmason", phone: "(02) 6747 7998", image: "images/f-41.jpg", mail:"robert.nolan@live.com", postcode: "BH9 4NG"  },
        { id: 4, parentId: 1, name: "Callum Anderson", title: "System operator", phone: "(03) 5314 0473", image: "images/f-43.jpg", mail:"callum.anderson@live.com", postcode: "HR6 8ZF"  },
        { id: 5, parentId: 4, name: "Courtney John", title: "System operator", phone: "(03) 5314 0473", image: "images/f-42.jpg", mail:"courtney.john@live.com", postcode: "OL4 6WF"  }
    ]
});

如果我将组织负责人 Elizabeth Horton 的顺序更改为 dataSource 的底部,例如:


$('#people').getOrgChart({
    theme: "vivian",
    primaryColumns: ["name", "title", "phone", "mail", "postcode"],
    imageColumn: "image",
    gridView: true,
    dataSource:[            
        { id: 2, parentId: 1, name: "Emily Horton", title: "Fork lift operator", phone: "(08) 9015 4407", image: "images/f-45.jpg", mail:"emily.horton@live.com", postcode: "BA5 0AP"  },
        { id: 3, parentId: 1, name: "Robert Nolan", title: "Blockmason", phone: "(02) 6747 7998", image: "images/f-41.jpg", mail:"robert.nolan@live.com", postcode: "BH9 4NG"  },
        { id: 4, parentId: 1, name: "Callum Anderson", title: "System operator", phone: "(03) 5314 0473", image: "images/f-43.jpg", mail:"callum.anderson@live.com", postcode: "HR6 8ZF"  },
        { id: 5, parentId: 4, name: "Courtney John", title: "System operator", phone: "(03) 5314 0473", image: "images/f-42.jpg", mail:"courtney.john@live.com", postcode: "OL4 6WF"  },
        { id: 1, parentId: null, name: "Elizabeth Horton", title: "Founder", phone: "(03) 9252 4642" , image: "images/f-46.jpg", mail:"elizabeth.horton@live.com", postcode: "PH2 2SR" }
    ]
});

我收到了这个错误:

未捕获的类型错误:无法读取 null 的属性“_aZ”

所以我希望回答我自己的问题可以帮助其他有同样问题的人。

干杯!

【讨论】:

    【解决方案2】:

    除了在孩子之前定义父母,如果您不想在 1100 人 JSON 数据结构中手动硬编码 idparentId 值,您还需要对 getorgchart.js 进行以下修改:

    从这里:

    getOrgChart.prototype.loadFromJSON = function(c) {
        this._aB = [];
        this._a9 = 0;
        this._a8 = 0;
        this._au = [];
        this._aj = [];
        this._aO = [];
        this._a7 = new getOrgChart.person(-1, null, null, 2, 2);
        for (var a = 0; a < c.length; a++) {
            var e = c[a];
            var b = e[Object.keys(e)[0]];
            var d = e[Object.keys(e)[1]];
            delete e[Object.keys(e)[0]];
            delete e[Object.keys(e)[0]];
            this.createPerson(b, d, e)
        }
        this.draw()
    };
    

    到这里:

    getOrgChart.prototype.loadFromJSON = function(c) {
        this._aB = [];
        this._a9 = 0;
        this._a8 = 0;
        this._au = [];
        this._aj = [];
        this._aO = [];
        this._a7 = new getOrgChart.person(-1, null, null, 2, 2);
        for (var a = 0; a < c.length; a++) {
            var e = c[a];
            var b = e['id'];
            var d = e['parentId'];
            delete e['id'];
            delete e['parentId'];
            this.createPerson(b, d, e)
        }
        this.draw()
    };
    

    Object.keys(e)[0]Object.keys(e)[1] 假设 idparentId 是“人”对象中的前两个键,如果您没有先定义它们,则实际上不会是真的。

    将代码更新为以下代码允许您在初始化之前动态生成dataSource 参数。

    【讨论】:

      猜你喜欢
      • 2021-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-07
      • 2018-06-28
      • 2022-06-18
      • 2017-06-07
      • 1970-01-01
      相关资源
      最近更新 更多