分享

EasyUI实现异步加载Tree

 WindySky 2017-03-17
Html内容:
  1. <fieldset style="height: 350px;">  
  2.     <ul id="taskTree" style="height:400px;width:250px;overflow: auto;"></ul>                      
  3. </fieldset>  

 

js内容:

[javascript] view plain copy
print?
  1. $('#taskTree').tree({  
  2.     checkbox: false,  
  3.     url: url,  
  4.     animate:true,  
  5.     lines:true,  
  6.     onClick:function(node){  
  7.         alert(node.text);  
  8.     },  
  9.     onBeforeExpand:function(node,param){                         
  10.         $('#taskTree').tree('options').url = ctx + "/rims/rescue/loadRescueTaskTreeRootNodes.do?parentId="+node.id;                  
  11.     }  
  12. });  


后台内容:

  1. JsonArray tree = new JsonArray();  
  2. JsonArray childs = new JsonArray();  
  3.       
  4. for(DisaRescueTaskView tView:tasks){  
  5.     JsonObject node = new JsonObject();  
  6.     node.addProperty("id", tView.getId());  
  7.     node.addProperty("text", tView.getName());  
  8.     node.addProperty("state", "closed");  
  9.     node.addProperty("icon", getTreeIconByRescueTaskMsg(tView));  
  10.     childs.add(node);  
  11. }  
  12.   
  13. JsonObject root = new JsonObject();  
  14. root.addProperty("id", "root");  
  15. root.addProperty("text", "救援任务");  
  16. root.addProperty("icon", "icon-ok");  
  17. root.add("children", childs);  
  18.       
  19. tree.add(root);  
  1. this.printOut(tree.toString());  


注:当前节点的state属性设置成:closed,则展开该节点时,会异步展开这个节点下的所有子节点。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约