0

I'm using ngjstree (https://github.com/ezraroi/ngJsTree) and i would like populate tree with an Ajax call; i looked up documentation and some examples, but i didn't find anything helpful. I know that is similar to jsTree, and checked out the documentation, i found that is possible populate the tree in this way:

$('#tree').jstree({
    'core' : {
        'data' : {
            'url' : function (node) {
                return node.id === '#' ?
                'ajax_roots.json' :
                'ajax_children.json';
         },
     'data' : function (node) {
         return { 'id' : node.id };
      }
    }
});

In ngjstree i can't call my tree in the same way ($('#tree').jstree), because i have a different structure. in particular case, i have this html:

<div ng-controller="treeCtrl as vm">
    <div js-tree="vm.treeConfig" ng-model="vm.treeData" tree="vm.treeInstance"></div>
</div>

I try to populate tree in the controller like this:

vm.treeData = { 
    core : { 
        html_titles : true
    },
    plugins : ["themes", "json_data", "ui"],
    json_data : {
        "ajax" : {
        "url" : myUrl,
        "data" : function (n) {
            return { 
                id : n.attr ? n.attr("id") : 0,
                node_type : n.attr ? n.attr("rel") : '',
                site_id: n.attr ? n.attr("site_id") : ''
            };
        }
    }
}

But this return always a tree with only one node, while if I open the same ajax call on browser, return more nodes.

Is it possible make the same things like jstree? am i doing any errors?

Sorry for the trivial question, but I'm a beginner about it.

Thanks in advance

Regards

Giordano
  • 5,422
  • 3
  • 33
  • 49
  • If you are using `**ng**jstree ` (with angular) why don't you just set the model with the json that you serialized from the ajax response? – Mosh Feu Feb 17 '16 at 15:08
  • Because i think that in this way i can load also the subnodes. look at this http://stackoverflow.com/questions/8078534/jstree-loading-subnodes-via-ajax-on-demand. am i wrong? – Giordano Feb 17 '16 at 15:31
  • I'm not familiar with the plugin but it's seems that the plugin support sub nodes too.. (http://i.stack.imgur.com/SmylB.png) You just take care about the thing that the model always show be updated. – Mosh Feu Feb 17 '16 at 16:13

0 Answers0