jquery jsTree 总结

最近在项目中用到了jquery jstree ,在此做下总结,引入

<script type="text/javascript" src="${ctx }/js/jQuery/jquery.js"></script>
<script type="text/javascript" src="${ctx }/js/jQuery/jstree/jquery.jstree.js"></script>

jquery jstree 的基本用法可以参考官网demo : http://www.jstree.com/

官网的例子每次加载数据都是一次性全部加载,当数据节点较多时,会造成性能问题。能不能采用按需加载呢,

原始ajax例子:

"json_data" : {

$(target).jstree({ 
"json_data" : { // This tree is ajax enabled - as this is most common, and maybe a bit more complex // All the options are almost the same as jQuery's AJAX (read the docs) "ajax" : { // the URL to fetch the data "url" : "/static/v.1.0pre/_demo/server.php", // the `data` function is executed in the instance's scope // the parameter is the node being loaded // (may be -1, 0, or undefined when loading the root nodes) "data" : function (n) { // the result is fed to the AJAX request `data` option return { "operation" : "get_children", "id" : n.attr ? n.attr("id").replace("node_","") : 1 }; } } }
});

按需加载,即点击父节点后,再加载子节点数据

    "json_data_on_demand" : {
                         "ajax" : {
                               "url" : function(node){
                                   var nodeId = "";
                                   var url = "";
                                   if(node==-1){        //如果是父节点,则返回-1
                                       url = "../data/navigator-catalog!get.action?parentid="+parentId;
                                   }
                                   else {               //否则,即是子节点
                                       nodeId = node.attr('id');
                                       url = "../data/navigator-catalog!get.action?parentid="+nodeId;
                                   }
                                   return url;
                               },
                               "success" : function(html){
                                   container.data("init","true");
                                   return html.content; //将数据返回给
                               },
                               "error" : function(message){
                               }
                                }
                          }, 

 

 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

转载于:https://www.cnblogs.com/justincai/archive/2012/09/12/2682321.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值