如何使用orgChart添加子级? [英] How to add children using orgChart?

查看:725
本文介绍了如何使用orgChart添加子级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用orgChart创建了一个树形图. 代码:

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' }
              );
            });
          }
        });

图生成工作正常. 我需要在使用ajax的节点上单击时添加子节点.

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

屏幕截图:

推荐答案

您可以参考此 demo 在codepen.io上.

You can refer to this demo on codepen.io.

通常,您可以使用以下形式调用orgchart插件的方法:)

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

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

这篇关于如何使用orgChart添加子级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆