English 中文(简体)
如何用“jstree”jquery plugin——不使用jax
原标题:how to append json variable as child nodes using "jstree" jquery plugin - no ajax

I have a jsTree using the json data format. Loading the root nodeset is fine.

My problem is how to append child nodes to the parent node that was clicked.

ANY help would be appreciated.

感谢!

    $("#tree-cat1")
    .bind("open_node.jstree", function (event, data) {
        console.log(data.rslt.obj.attr("id"));
        //eval(loadChild());
        //at this point i need to append the result of loadChild() to the tree under the relevant node
    })
    .jstree({
        "json_data": {
            "data": eval(loadRoot())
        },
        "themes": {"theme": "classic","dots": true,"icons": true},
        "plugins": ["themes", "json_data", "ui"]
    })

function loadRoot() {
    return "[{ data : A node , state : closed , attr :{ id : A }}]";
}
function loadChild() {
    return "[{ data : A1 node , attr :{ id : A1 }}]";
}
问题回答

http://www.jstree.com/documentation/json_data”rel=“nofollow” jsTree docu

在这里,你们需要改观目的地,尝试它。

html:

<div id="tree-cat1"></div>

j)

 $("#tree-cat1").jstree({
    "plugins": ["themes", "json_data", "ui"],
    "themes": {"theme": "classic","dots": true,"icons": true},
    "json_data": {
          //root elements
        "data": [{"data": A node ,"state": closed ,"attr":{"id": A }}], 
        "ajax": {
            "type":  POST ,
            "data": {"action":  getChildren },
            "url": function (node) { 
                var nodeId = node.attr( id ); //id="A"

                return  yuorPathTo/GetChildrenScript/  + nodeId;
            },
            "success": function (new_data) {
                //where new_data = node children 
                //e.g.: [{ data : A1 node , attr :{ id : A1 }}, { data : A2 node , attr :{ id : A2 }}]
                return new_data;
            }
        }
    }
});

OLD PART
something like that will populate opened node with children, if not already done:

 ...
    "json_data": {
          //root elements
        "data": [{"data": A node ,"state": closed ,"attr":{"id": group_A }}], 
        "ajax": {
            "type":  POST ,
            "data": {"action": act.GET_GROUPREPORTS},
            "url": function (node) { 
                var nid = node.attr( id ); //id="group_A"
                nid = nid.substr(nid.lastIndexOf( _ )+1);

                return module.getDBdata_path + nid;
            },
            "success": function (data) {
                var rid, new_data = data;

                if (typeof data[0] ===  undefined ) {
                    new_data = [];
                    for (rid in data) {
                        if(data.hasOwnProperty(rid)) {
                          new_data.push({"data": data[rid], 
                               "attr": {"id":  rprefix_ +rid, 
                                        "title":    , 
                                        "rel":  report ,
                                        "href": module.repView_path+rid
                              }
                          });
                        }
                    }
                }
                return new_data;
            }
        }
    }, ...




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签