Mohammad Sadiq Shaikh
Mohammad Sadiq Shaikh

Reputation: 3200

SpaceTree how to add subtree on node click

I have written the following code which shows the error:

Cannot read property 'children' of null

I want the children to be loaded when the node is clicked.

request:function(nodeId, level, onComplete)
            {
                alert(nodeId+'p   '+level+' p  '+onComplete);
                var i=0;
              $.ajax({
                    url: '/users/userhierarchy.json?id=' + nodeId,
                   dataType: 'json',
                   success: function(json){
                        var tree = json;
                        var subtree = $jit.json.getSubtree(tree, nodeId);

                        $jit.json.prune(subtree, level);
                        i++;
                        ans= {
                            'id': nodeId,
                            'children': subtree.children
                        };
                        onComplete.onComplete(nodeId, ans);

                    },

                });

            }

Upvotes: 3

Views: 916

Answers (0)

Related Questions