Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.8k views
in Technique[技术] by (71.8m points)

javascript - How to get checked nodes in jquery jstree

I have created one jquery jstree and it's working fine. Now the problem is how to get the the checked nodes details.

For Creating JStree The code is:

$(function () {
$("#tree").jstree({ 
    "json_data" : {
        "data" : [
            {"data":"pe_opensourcescanning","id":0,"pId":-1,"children":  [{"data":"tags","id":30,"pid":0},{"data":"branches","id":29,"pid":0},{"data":"trunk","id":1,"pid":0,"children":[{"data":"import-export","id":28,"pid":1},{"data":"custom_development","id":12,"pid":1},{"data":"Connectors","id":7,"pid":1},{"data":"support","id":6,"pid":1},{"data":"Installation-Configuration","id":5,"pid":1},{"data":"backup","id":2,"pid":1}]}]}
        ]
    },
    "plugins" : [ "themes", "json_data", "checkbox", "ui" ]
}).bind("select_node.jstree", function (e, data) { alert(data.rslt.obj.data("id")); });

Now while getting checked nodes i need all the attributes values for those checked elements. Say like for "tags" the json object looks like {"data":"tags","id":30,"pid":0}, so if user select tag i need the value of "data" And "id". i have tried to write some code but unfortunately that is not working.

Getting Checked Nodes.

$("#" +div2.childNodes[i].id).jstree("get_checked",null,true).each 
      (function () { 
         alert(this.data);
         alert(this.id);

 }); 

Kindly give me a solution.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As the Author of jstree (Ivan Bozhanov) points out on google-Groups Discussion regarding get_checked, it can also be achieved using the following:

$('#tree').jstree(true).get_selected();

This returns a List of the IDs, e.g. ["j1_2"] or ["j1_2", "j1_3", "j1_1"]

Check out the fiddle by Ivan Bozhanov himself on: jsfiddle-Example get_selected


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...