JsTree_json异步传值

来源:互联网 发布:比较两组数据的相似度 编辑:程序博客网 时间:2024/06/05 15:22

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

  }

]

 

原创粉丝点击