开发者

Access jstree metadata in double-click and ajax calls

I'm using the jQuery jsTree plugin to create a tree view. It is populated dynamically with json data, where each node contains metadata. When I expand a node I would like to be able to access node metadata and pass it as part of the AJAX call for new json data. I also want to access the metadata when I double-click a node. Can someone suggest what code I need to insert into the code examples be开发者_开发百科low?

$("#tree").jstree({ 
    "json_data" : {
        "ajax": {
            "url": "/url",
            "data": function(n) {
                // NEED METADATA HERE
            }
        }
    }
});

$("#tree").delegate("a", "dblclick", function(e) {
    // NEED METADATA HERE
});


I'm not sure about doing it in the data function but in instead of delegate you can do this.

$('#tree').bind("select_node.jstree", function(event, data){
console.log(data.rslt.obj.data('jstree')); //data.rslt.obj.data('jstree') will contain all metadata you have set
});


 $("#tree").jstree({ 
    "json_data" : {
        "ajax": {
            "url": "/url",
            "data": function(n) {
                // NEED METADATA HERE
                var node = $.data(n[0], "jstree");
                alert(node); // THIS IS YOUR REQUIRED META DATA
            }
        }
    }
});

$("#tree").delegate("a", "dblclick", function(e) {
    // NEED METADATA HERE
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜