Jstree Demo

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.

<script type="text/javascript" src="./_lib/jquery.js"></script>
<script type="text/javascript" src="./jquery.jstree.js"></script>

 

2.

$(function () {
	$.ajaxSetup({cache:false});//ajax request don't use the cache
$("#jsonDemo").jstree({ 
		// List of active plugins
		"plugins" : [ 
			"themes","json_data", "ui"
		],
		// I usually configure the plugin that handles the data first
		// This example uses JSON as it is most common
		"json_data" : { 
			"data" : [{"attr":{"id":"1204","isLast":"false","name":"A Node"},
				          "data":"A Node",
				         "metadata":{"id":"1204","isLast":"false","name":"A Node"},
				          "state":"closed"},
			          {"attr":{"id":"1205","isLast":"true","name":"B Node"},
			          	"data":"B Node",
			          	"metadata":{"id":"1205","isLast":"true","name":"B Node"},
			          	"state":"close"}
			         ],
			"ajax" : { "url" : "./_demo/_tree_json.json",
						     "data": function (n){
	                            return{
 	                                //set the url request param,multi param separate by ,
			                            "parentId" : n.attr ? n.attr("id") : "null",
			                            "name":  n.attr ? n.attr("name") : "null"
	                            };
                        }
			 }
		},	
	   "themes" : {
	         "theme" : "classic", //apple,default,if in ie6 recommented you use classic
	         "dots" : true,
	         "icons" : true
	   }
	})
	.bind("select_node.jstree",function(event,data){  
			if("true" == data.rslt.obj.attr("isLast")){ 
				 //get the attrs data you set in the attrs field;
			    alert(data.rslt.obj.attr("id")+data.rslt.obj.attr("isLast"));
			    //you can do something here...
			}else{
				//toggle node refer to the id setted in the metadata
				//get the metadata id field value : jQuery.data(data.rslt.obj[0], "id");
				//The metadata id value should be different to each other !!!
				//otherwise, the toggle_node will work incorrect !!!
				$("#jsonDemo").jstree("toggle_node","#"+jQuery.data(data.rslt.obj[0], "id"));
			}    
    })
    // prevent the default event of the link 
	.delegate("a", "click", function (event, data) { event.preventDefault(); })
	;
});

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

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值