JsTree Demo view

本文介绍JsTree插件的使用方法,包括配置项说明、事件绑定及节点操作等关键功能。通过示例展示了如何加载JSON数据并实现节点点击事件,同时介绍了主题设置与IE6兼容性的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

JsTree Demo

Version: jstree pre 1.0 stable
Add a demo for jstree in demo/index.html
Integrate the usage of metadata, click the node event ,attrs,toggle nodes and ajax json in jstree
Changed apple theme and classic theme background fixed for in ie6.
1.

 

Html代码   收藏代码
  1. <script type="text/javascript" src="./_lib/jquery.js"></script>  
  2. <script type="text/javascript" src="./jquery.jstree.js"></script>  

 

2.

 

Js代码   收藏代码
  1. $(function () {  
  2.     $.ajaxSetup({cache:false});//ajax request don't use the cache  
  3. $("#jsonDemo").jstree({   
  4.         // List of active plugins  
  5.         "plugins" : [   
  6.             "themes","json_data""ui"  
  7.         ],  
  8.         // I usually configure the plugin that handles the data first  
  9.         // This example uses JSON as it is most common  
  10.         "json_data" : {   
  11.             "data" : [{"attr":{"id":"1204","isLast":"false","name":"A Node"},  
  12.                           "data":"A Node",  
  13.                          "metadata":{"id":"1204","isLast":"false","name":"A Node"},  
  14.                           "state":"closed"},  
  15.                       {"attr":{"id":"1205","isLast":"true","name":"B Node"},  
  16.                         "data":"B Node",  
  17.                         "metadata":{"id":"1205","isLast":"true","name":"B Node"},  
  18.                         "state":"close"}  
  19.                      ],  
  20.             "ajax" : { "url" : "./_demo/_tree_json.json",  
  21.                              "data"function (n){  
  22.                                 return{  
  23.                                     //set the url request param,multi param separate by ,  
  24.                                         "parentId" : n.attr ? n.attr("id") : "null",  
  25.                                         "name":  n.attr ? n.attr("name") : "null"  
  26.                                 };  
  27.                         }  
  28.              }  
  29.         },    
  30.        "themes" : {  
  31.              "theme" : "classic"//apple,default,if in ie6 recommented you use classic  
  32.              "dots" : true,  
  33.              "icons" : true  
  34.        }  
  35.     })  
  36.     .bind("select_node.jstree",function(event,data){    
  37.             if("true" == data.rslt.obj.attr("isLast")){   
  38.                  //get the attrs data you set in the attrs field;  
  39.                 alert(data.rslt.obj.attr("id")+data.rslt.obj.attr("isLast"));  
  40.                 //you can do something here...  
  41.             }else{  
  42.                 //toggle node refer to the id setted in the metadata  
  43.                 //get the metadata id field value : jQuery.data(data.rslt.obj[0], "id");  
  44.                 //The metadata id value should be different to each other !!!  
  45.                 //otherwise, the toggle_node will work incorrect !!!  
  46.                 $("#jsonDemo").jstree("toggle_node","#"+jQuery.data(data.rslt.obj[0], "id"));  
  47.             }      
  48.     })  
  49.     // prevent the default event of the link   
  50.     .delegate("a""click"function (event, data) { event.preventDefault(); })  
  51.     ;  
  52. });  

demo page:http://johntang.github.com/JsTree/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值