json数据格式:
[
{
/"attributes/" : { /"id/" : /"1/" },
/"data/" : {/"title/" : /"节点1/",/"attributes/" : { /"href/" : /"http://jstree.com/" }} ,
/"state/": /"closed/"
}
,
{
/"attributes/" : { /"id/" : /"2/" },
/"data/" : {/"title/" : /"节点2/",/"attributes/" : { /"href/" : /"http://2jstree.com/" }},
/"state/": /"closed/"
}
]
注:第一个attributes是为节点添加个属性id,这个id可以从前台传过来,用于取该id节点的子节点;
第二个data是节点数据信息;
第三个state为closed时表示前台该节点状态为关闭,也只有节点状态为关闭时点击节点会触发异步回传、当state为open时表示前台节点状态为打开,点击时并不会异步回传。
在后台可以用Request["id"]取到节点id值
下面为前台异步json取节点方法
<script type="text/javascript" class="source">
$(function() {
$("#async_json_2").tree({
data: {
type: "json",
async: true,
opts: {
method: "POST",
url: "/JsTree/TwoData.aspx"
}
}
});//end $(function()
}); //end $(function()
</script>
<div class="demo" id="Div1">
下面为带子节点的数据格式:
[
{
/"attributes/" : { /"id/" : /"1/" },
/"data/" : {/"title/" : /"Long format demo/",
/"attributes/" : { /"href/":/"http://jstree.com/" }
} ,
/"children/" : [
{ /"data/" : /"Child node 1/",/"state/": /"closed/" },
{ /"data/" : /"node 2/" ,/"state/": /"closed/"}
]
}
,
{
/"attributes/" : { /"id/" : /"2/" },
/"data/" : {/"title/" : /"2Long format demo/",
/"attributes/" : { /"href/" : /"http://2jstree.com/" }
} ,
/"state/": /"closed/"
}
]