Management of the jit.js library with json

1

Look, I have a .js file that loads a json and is working. In principle you will be charged a% full% co, and then doing json expands the children of the clicked node:

  • When the page loads:

    //load json data
    st.loadJSON(json);
    //compute node positions and layout
    st.compute();
    //optional: make a translation of the tree
    st.geom.translate(new $jit.Complex(-200, 0), "current");
    //emulate a click on the root node.
    st.onClick(st.root);
    //end
    
  • When a click is made on the node:

    onCreateLabel: function(label, node){
        label.id = node.id;            
        label.innerHTML = node.name;
        label.onclick = function(){
            st.onClick(node.id);
        };
    

I have introduced a modification, so that at first a click is loaded and then a larger one when clicking on a node:

 onCreateLabel: function(label, node){
        label.id = node.id;            
        label.innerHTML = node.name;
        label.onclick = function(){

        var http = new XMLHttpRequest();
        var url = "inicio_pru.php";
        var params = "callFunction=arbol_completo";
        http.open("POST", url, true);
        //Send the proper header information along with the request
        http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        http.send(params);
        http.onreadystatechange = function() {//Call a function when the state changes.
                    if(http.readyState == 4 && http.status == 200) {

                             json=http.responseText;
                             st.loadJSON(json);
                              //compute node positions and layout
                             st.compute();
                              //optional: make a translation of the tree
                             st.geom.translate(new $jit.Complex(-200, 0), "current");
                             //emulate a click on the root node.
                             st.onClick(node.id);
                      }
            };

The page load is correct, but when I click on the label of a node, I get the following error:

  

jit.js: 8795 Uncaught TypeError: Can not read property 'id' of undefined

The json is like this:

'{"id":"38358","name":"Anillo Critico","data":{"$color":"#008000","$type":"circle"},"children":[]}';    

With what I deduce that when doing json , a node is created with a st.loadJSON(json) , a id and a name , and one is created for each data of id . When I do json in one, I send click the st.onClick(node.id) of that in particular.

Can you help me? Thank you very much in advance.

    
asked by Mayte 14.09.2016 в 07:59
source

0 answers