将值从dynatree传递给JSON

时间:2015-04-07 06:09:07

标签: json dynatree jquery-dynatree

我正在创建一个dynatree结构并尝试将树的节点转换为JSON值。怎么做?我能够获取JSON对象但无法获取该JSON对象的值。

以下是创建dynatree并将其转换为JSON的代码:

     <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>

我得到的输出是[object Object,object Object]。我在这里犯的错是什么?

0 个答案:

没有答案