JsTree_json異步傳值

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

  }

]

 

發佈了27 篇原創文章 · 獲贊 0 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章