Loading nodes in JIT SpaceTree

921 Views Asked by At

I try to use the SpaceTree from JIT and i realy need some help. The problem is when try to load the tree from anothe array.

json.php

<?php
$temp = array(
    'id' => "node02",
    'name' => "roey",
    'data' => '',
    'children' => json_encode(array(
        'id' => "node13",
        'name' => "Some Node",
        'data' => '',
        'children' => '',

    )),
);
echo json_encode($temp);

my spacetree.js:

....
function init(){
$.getJSON('json.php', function(json){
    var json = json;
....
st.loadJSON(json);

The JSON that i receive is as expected, but the script dont load it.

Does anyone see the problem and can help me with that?

2

There are 2 best solutions below

1
On
  1. Delete from your code "var json = json". Variable json already declared in that function.
  2. If "st.loadJSON(json);" not in function(json){ your code }. Variable json is local for function and can only be referenced within the function it is declared.
0
On

i to was facing the same problem, JIT SpaceTree uses array of arrays for the children key, the php array should be like this

`<?php
$temp = array(
'id' => "node02",
'name' => "roey",
'data' => '',
'children' => array(array(
    'id' => "node13",
    'name' => "SomeNode",
    'data' => '',
    'children' =>array(),
),array(
    'id' => "node14",
    'name' => "SomeNode",
    'data' => '',
    'children' =>array(),
),
)
);
echo json_encode($temp);
?>`

hope this helps and saves time 4 others :)