码迷,mamicode.com
首页 > Web开发 > 详细

【JSTREE】使用fuction,和异步传值 005

时间:2016-12-28 01:13:49      阅读:382      评论:0      收藏:0      [点我收藏+]

标签:his   关闭   on()   dem   class   ima   attribute   javascrip   node   

技术分享
$(‘#tree‘).jstree({
    ‘core‘ : {
        ‘data‘ : function (obj, cb) {
            cb.call(this,
              [‘Root 1‘, ‘Root 2‘]);
        }
    }});
View Code
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/"

  }

]

 

【JSTREE】使用fuction,和异步传值 005

标签:his   关闭   on()   dem   class   ima   attribute   javascrip   node   

原文地址:http://www.cnblogs.com/flydkPocketMagic/p/6227774.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!