function recursive_simplify(node){
if(node.children){
for(var i =0;i<node.children.length;i++){
node.children[i] = recursive_simplify(node.children[i])
}
}
delete node['metadata'];
return node
}
$('#click_button').click(function(){
var tree=$.jstree._reference('#tree');
var selected = tree.get_selected();
var result = [];
for(var i=0, selectedLength = selected.length; i<selectedLength;i++)
{
var selectedJson = tree.get_json(selected[i],['id','rel','data-bin','data-pos','class'])[0];
selectedJson = recursive_simplify(selectedJson);
result.push(selectedJson);
}
document.write(JSON.stringify(result))
});
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Sample Title</title>
<script src="jquery-1.6.min.js"></script>
<script src="jquery.jstree.js"></script>
<script>
$(document).ready(function(){
$('#tree').jstree({
"themes" : {
"theme" : "apple",
"dots" : true,
"icons" : false
},
"json_data" : {
"data" : [
{
"data" : "Networks",
"metadata" : { id : "network" },
"children" : [
{
"data":"Publishers",
"metadata":{ id : "publisher" },
"children" : [
]
},
{
"data":"Advertisers",
"metadata" : { id : "advertiser" },
"children":[
]
}]
}
]
},
"plugins" : [ "themes", "json_data", "ui"]
});
$('#click_button').click(function(){
var tree=$.jstree._reference('#tree');
var selected = tree.get_selected();
var result = [];
for(var i=0, selectedLength = selected.length; i<selectedLength;i++)
{
var selectedJson = tree.get_json(selected[i])[0];
result.push(selectedJson);
}
document.write(JSON.stringify(result))
});
});
</script>
</head>
<body>
<div id="tree"></div>
<button id="click_button">Export</button>
</body>
</html>