2

I use in Django + django-mptt to complete a win-explorer-tree-like interface with jstree:

{% load mptt_tags %}
var nodedata = {
    "data": {
    {% recursetree nodes %}
    "data": "{{ node.nodename }}",   
    "id": "{{ node.id }}", 
    "state":"open",
    "children": [{ {{ children }} }],
    {% endrecursetree %}
    }
};

it works fine when every node just has one child. but when the users create more than one child node, it expands in jstree like:

var nodedata = {
    "data": {

    "data": "following1",   
    "id": "1", 
    "state":"open",
    "children": [{ 
    "data": "level3",   
    "id": "4", 
    "state":"open",
    "children": [{ 
    "data": "level 4",   
    "id": "5", 
    "state":"open",
    "children": [{ 
    "data": "New node",   
    "id": "6", 
    "state":"open",
    "children": [{ 
    "data": "New node 2",   
    "id": "7", 
    "state":"open",
    "children": [{  }],
     }],

    "data": "kkk",   
    "id": "8", 
    "state":"open",
    "children": [{  }],
     }],
     }],
     }],

    }
};

the "kkk" node shows but "New Node" and "New Node 2" do not show up.

I am seeking some advice or is it a better way to represent this tree?

Gagiel
  • 45
  • 5

1 Answers1

1

I think there is an error in your json variable. You have:

"children": [{
    "data": "New node",
    "id": "6",
    "state":"open",
    "children": [{
        "data": "New node 2",
        "id": "7",
        "state":"open",
        "children": [{  }],
    }],
    "data": "kkk",
    "id": "8",
    "state":"open",
    "children": [{  }],
}],

Each node in "children" array must be in separate {}, divided by comma.

Eugene Soldatov
  • 9,755
  • 2
  • 35
  • 43