JSOrgChart

1. Build a org tree use jquery

先动态构建一组UL / LI 对象。然后运行

$("#org").jOrgChart();

 function BuildOrg() {
        var li = document.createElement("li");
        //$("#org").append("<li>hello world fdd</li>");
        $("#org").append(li);
        var root = getObjects(orgData, "ManagerID", "0");
        li.innerHTML = getShow(root[0]);
        BuildOrgNode(li, root[0].MemberID);

    }

  

 function BuildOrgNode(node, id) {
        var children = getObjects(orgData, "ManagerID", id);
        if (children.length > 0)
        {
            //create UL
            var ul = document.createElement("ul");
            node.appendChild(ul);

            $.each(children, function (i, item) {
                var li = document.createElement("li");
                li.innerHTML = getShow(item);
                ul.appendChild(li);
                BuildOrgNode(li, item.MemberID);
            });
        }
    }

    function getObjects(obj, key, val) {
        var objects = [];
        for (var i in obj) {
            if (!obj.hasOwnProperty(i)) continue;
            if (typeof obj[i] == ‘object‘) {
                objects = objects.concat(getObjects(obj[i], key, val));
            } else if (i == key && obj[key] == val) {
                objects.push(obj);
            }
        }
        return objects;
    }

  

时间: 2024-10-13 08:14:36

JSOrgChart的相关文章