职业IT人-IT人生活圈

 找回密码
 成为会员
搜索
查看: 766|回复: 2

Jstree Demo

[复制链接]
只学java 发表于 2011-9-6 14:11 | 显示全部楼层 |阅读模式
  
JsTree Demo
Version: jstree pre 1.0 stable
Old versions: http://code.google.com/p/jstree/downloads/list
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代码  
<script type="text/javascript" src="./_lib/jquery.js"></script>  
<script type="text/javascript" src="./jquery.jstree.js"></script>  

<script type="text/javascript" src="./_lib/jquery.js"></script>
<script type="text/javascript" src="./jquery.jstree.js"></script>2.
Js代码  
$(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(); })   
    ;   
});  

$(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/
Integrate demo page:http://johntang.github.com/JsTree/demo.html
Jstree demo page:http://johntang.github.com/JsTree/_demo/


爱车车 发表于 2011-9-6 14:11 | 显示全部楼层
自从用了 jquery ztree 后,就不再用 jstree 了

曾经的小孩 发表于 2011-9-6 14:12 | 显示全部楼层
哥一直都是自己写tree,比那好用多了,想要什么功能就有什么功能...
您需要登录后才可以回帖 登录 | 成为会员

本版积分规则

QQ|手机版|小黑屋|网站帮助|职业IT人-IT人生活圈 ( 粤ICP备12053935号-1 )|网站地图
本站文章版权归原发布者及原出处所有。内容为作者个人观点,并不代表本站赞同其观点和对其真实性负责,本站只提供参考并不构成任何投资及应用建议。本站是信息平台,网站上部分文章为转载,并不用于任何商业目的,我们已经尽可能的对作者和来源进行了通告,但是能力有限或疏忽造成漏登,请及时联系我们,我们将根据著作权人的要求立即更正或者删除有关内容。

GMT+8, 2024-5-2 11:17 , Processed in 0.133490 second(s), 20 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表