欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Ext异步加载树(TREE) treeextjson 

程序员文章站 2022-07-12 17:26:20
...
jsp页面:

  var tree;
  var ne;
  var rightshowMenu;
  Ext.onReady(function(){
  Ext.BLANK_IMAGE_URL="ext/resources/images/aero/s.gif";      
   
  var loader = new Ext.tree.TreeLoader({
    url: "bookShop.do?parameter=treedata"
   });
  
  loader.on("beforeload", function(loader, node){
     this.baseParams.id = (node.id);
    });
  var root = new Ext.tree.AsyncTreeNode({
    id: "root",
    text: "",
    draggable: true //设置根节点是否可拖拽
   });
  
  tree = new Ext.tree.TreePanel({
    renderTo: "tree-div",
    useArrows: true,
       autoScroll: true,
       animate: true,
       containerScroll: true,
       rootVisible: false,
       border: false,
       root:root,
    enableDD: true//允许拖拽
   // listeners:{contextmenu:showMenu}
   });
  <%
  for(int i=0;i<listrose.size();i++)
  {
    Rose rose=listrose.get(i);
  %>
  var croot=new Ext.tree.AsyncTreeNode({
  id:"<%=rose.getId()%>",
  text:"<%=rose.getName()%>",
  allowDrag: false, // 在部门树里面,组织不支持拖拽
     loader: loader
  });
  root.appendChild(croot);
  <%
  }
  %>
  tree.getRootNode().expand();
  });


java:
public ActionForward treedata(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String id = request.getParameter("id");
log.info("展开节点根据 节点ID::" + id + ",获取子节点信息!");
List<Rose> list = roseBiz.resutlRosebyid(id);

JSONArray json = new JSONArray();
if (null != id && id.length() > 0) {
for (Rose rose : list) {
JSONObject temp = new JSONObject();
temp.put("id", rose.getId());
temp.put("text", rose.getName());
json.add(temp);
}
}else
{
log.info("节点下为空!");
}
log.info("展开节点,获取节点下面的信息:格式化返回::" + json.toString());
writerJSON(response, json.toString());
return null;
}
相关标签: tree ext json