How to add children using orgChart?

与世无争的帅哥 提交于 2019-12-11 10:32:23

问题


I have create a tree diagram using orgChart. code:

var datascource = {
          'id': 1,
          'name': 'Lao Lao',
          'title': 'general manager',
          'children': [
            { 'id':2,'name': 'Bo Miao', 'title': 'department manager' },
            { 'id':3,'name': 'Su Miao', 'title': 'department manager'},
            { 'id':4,'name': 'Hong Miao', 'title': 'department manager' },
            { 'id':5,'name': 'Chun Miao', 'title': 'department manager' }
          ]
        };

        $('#chart-container').orgchart({
          'visibleLevel': 2,
          'pan': true,
          'data' : datascource,
          'nodeContent': 'title',
          'nodeId':'id',
          'createNode': function($node, data) {
            $node.on('click', function(event) {
              $('#chart-container').orgchart('addChildren', $node,
                {'id' : 7,  'name': 'Hong ', 'title': 'Test manager' }
              );
            });
          }
        });

Digram generation working fine. I need to add child nodes on click by nodes using ajax.

Screen shot:


回答1:


You can refer to this demo on codepen.io.

Generally, you can call the methods of orgchart plugin with the following form : )

var oc = $('#chart-container').orgchart{(...});
oc.method();


来源:https://stackoverflow.com/questions/50095479/how-to-add-children-using-orgchart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!