ezraroi / ngJsTree

Angular Directive for the famous JS Tree
http://ezraroi.github.io/ngJsTree/
MIT License
270 stars 98 forks source link

Getting error while openning Parent Node in Case of lazy loading. #64

Open Rabi-Narayan opened 8 years ago

Rabi-Narayan commented 8 years ago

jsfile.txt

Hi ezraroi, modified in the way u suggested to make empty array and pushed the response data but it failed to create child nodes and gives error while trying to open a parent node. treeCtrl: error from js tree - {"error":"nodata","plugin":"core","id":"core_05","reason":"Could not load node","data":"{\"id\":\"ajson1\"}"}

my config and data to load initial tree is like this.Given some initial data to populate tree because it is not creating any node in other ways. vm.treeData = [ { id : 'ajson1', parent : '#', text : 'Simple root node', state: { opened: false},children:true }, { id : 'ajson2', parent : '#', text : 'Root node 2', state: { opened: false},children:true }, ];

vm.treeConfig = {
    core : {
        multiple : false,
        animation: true,
        error : function(error) {
            $log.error('treeCtrl: error from js tree - ' + angular.toJson(error));
        },
        check_callback : true,
        worker : true
    },
    types : {
        default : {
            icon : 'glyphicon glyphicon-flash'
        },
        star : {
            icon : 'glyphicon glyphicon-star'
        },
        cloud : {
            icon : 'glyphicon glyphicon-cloud'
        }
    },
    version : 1,
    plugins : ['types','checkbox']
};

I am getting data from http service like this:

var promise = ravensService.getChildren();

I am calling the follwing function on "open_node" event of jsTree.But before this event i am getting above error :( vm.openChildNode = function() { vm.treeData.push(data.data); };

promise.then(function (data)
{
vm.treeData = data.data;
console.log(vm.treeData);
});

I have tried all the stuffs and working on same from days but unable to find solution.I am using jsTree in Angularjs.Since i am new to this please help in this regard.Thanks in advance.PFA for Js.

ezraroi commented 8 years ago

Hi, please write a plunker that reproduces your problem and I will try to look on it

Rabi-Narayan commented 8 years ago

Thanks for the reply ezraroi. Now i am doing ajax call inside the Jstree configuration itself.Now this issue is resolved.But can u please suggest me to get into solution for possibility of populating jstree by using REST services inside tree config ?If so is there any reference for guidance ?? Thanks in advance.

icfantv commented 8 years ago

@Rabi-Narayan, the right behavior in this case is to inject the necessary dependencies into your directive or controller before-hand either using resolve functions (for route navigation or, say, UIBS modals) or directly using promises.