开发者

Loading a tree with json dynamically

I'm designing a tree in JavaScript, and I'm trying to load a node, stored in a json file on the sever.

Pseudo-code JavaScript:

var nodeRoot = 
{
    level: 4,
    id: 12,
    data: ...,
    childs: Array() // the nodes, all similar to the root, but of level n-1
}

function downloadNodeData(_node){
    //initializing the request
    req.onreadystatechange=
        function(){
            //testing the request
            var nodeResult = eval("("+req.responseText+")");
            console.log(nodeResult);
            // ----- What now ? -----
        }开发者_如何学编程
    req.send(null);
}

I may have to call this function in several places (the idea is to load dynamically the tree nodes, depending of the user actions).

The point is that I can't find no way to update the value of the node which was called, once the request returns.

Is the only way to make a SetNodeByLevelAndId(_node,_level,_value) ?

Thank you for your help.


In the description of nodeRoot there is no attributes value. What do you want to update on _node (parameter given to your function).

If it is to replace _node by nodeResult, you have to copy attributes of nodeResult one by one to _node. Because other nodes which reference _node will use an old reference if you assign

_node = nodeResult
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜