将值从dynatree传递到JSON
我正在创建一个dynatree结构,并尝试将树的节点转换为JSON值。怎么做?我能够获取JSON对象,但无法获取该JSON对象的值 以下是创建动态树并将其转换为JSON的代码:将值从dynatree传递到JSON,json,dynatree,jquery-dynatree,Json,Dynatree,Jquery Dynatree,我正在创建一个dynatree结构,并尝试将树的节点转换为JSON值。怎么做?我能够获取JSON对象,但无法获取该JSON对象的值 以下是创建动态树并将其转换为JSON的代码: <script type="text/javascript"> $(function(){ // Attach the dynatree widget to an existing <div id="tree"> element // and pass the
<script type="text/javascript">
$(function(){
// Attach the dynatree widget to an existing <div id="tree"> element
// and pass the tree options as an argument to the dynatree() function:
$("#source").dynatree({
onActivate: function(node) {
// A DynaTreeNode object is passed to the activation handler
// Note: we also get this event, if persistence is on, and the page is reloaded.
alert("activated node"+node.data.title);
alert(tree);
},
children: [ // Pass an array of nodes.
{title: "source", isFolder: true,
children: [
{title: "field1"},
{title: "feiled2"}
]
},
{title: "group", isFolder: true,
children: [
{title: "field1"},
{title: "feiled2"}
]
}
]
});
var tree = $("#source").dynatree("getTree").toDict();
alert(tree);
var jsonObject = JSON.stringify(tree);
alert("json stringify"+jsonObject.tree);
});
</script>
$(函数(){
//将dynatree小部件附加到现有元素
//并将树选项作为参数传递给dynatree()函数:
$(“#来源”).dynatree({
onActivate:函数(节点){
//DynaTreeNode对象被传递给激活处理程序
//注意:如果启用了持久性,并且页面被重新加载,我们也会得到这个事件。
警报(“激活节点”+节点.数据.标题);
警报(树);
},
子项:[//传递一个节点数组。
{标题:“源”,isFolder:true,
儿童:[
{标题:“字段1”},
{标题:“feiled2”}
]
},
{标题:“组”,isFolder:true,
儿童:[
{标题:“字段1”},
{标题:“feiled2”}
]
}
]
});
var-tree=$(“#source”).dynatree(“getTree”).toDict();
警报(树);
var jsonObject=JSON.stringify(树);
警报(“json字符串化”+jsonObject.tree);
});
我得到的输出是[object object,object object]。我在这里犯了什么错误?我得到了上述问题的结果。最初我使用的是package.json,但它不起作用。然后我下载了一个json json-20140107.jar的jar文件,并导入到WEB_INF下的lid文件夹中。这对我很有用。