日期:2014-05-18  浏览次数:20657 次

jsp输出json,extjs接受的问题
Ext里的TreeLoader有个dataUrl初始值,现在给个jsp页面作为参数,jsp页面输出json数据!
  为什么树加载不了呢?

jsp页面(data.jsp)如下:
<%
String str="[";
str +="{id:'a1',text:'退出系统',icon:'images/Ext/example.gif',leaf:true,href:'jx.jsp'}";
str +=",{id:'a2',text:'返回首页',icon:'images/Ext/example.gif',leaf:true,hrefTarget:'_top',href:'jx.jsp'}";
str +=",{id:'a3',text:'密码修改',leaf:true,'cls':'cls','href':'jx.jsp'}";
str +="]";
out.println(str);
%>

===============================================
Extjs代码如下:
{
title:'标题',
border:false,
iconCls:'spgl',
autoScroll:true,
items:[{
  xtype:'treepanel',
  autoScroll:true,
  animate:true,
enableDD:false,
border:false,
rootVisible:false,
containerScroll: true,
root:root_spgl,
listeners:{"click":{fn:addTabs}},
width:198,
loader: new Ext.tree.TreeLoader({dataUrl:'data.jsp'})
}]
}

------解决方案--------------------
建议使用IE8的Debug或 是FF的Debug功能.判断出哪里出错了.
很久没接触了EXTjs,从你的程序里,没看出哪里不对啊
------解决方案--------------------
既然信息是固定的 直接在jsp里面
[
{'text':'系统状态信息','id':'systemOverview','leaf':'true','cls':'file',url : 'pages/status/statue.html'},
{'text':'iSCSITargets','id':'iSCSITargets','leaf':'true','cls':'file'}
]

就可以了


你的data.jsp的路径对不对 还有其他提示错不?
------解决方案--------------------
1、直接在地址栏里输入http://……/data.jsp
看看是否有结果?
如果没错,那就是extjs的部分了!
楼主最好把错误贴出来!
------解决方案--------------------
代码不完全 关键不是看load 而是 看

treepanel你的设置
JScript code
 
Ext.onReady(function(){
  // shorthand
  var Tree = Ext.tree;

  var tree = new Tree.TreePanel({
    el:'tree-div',
    autoScroll:true,
    animate:true,
    enableDD:true,
    containerScroll: true,
    loader: new Tree.TreeLoader({
      dataUrl:'http://localhost:8080/tree/menus.action'
    })
  });

  // set the root node
  var root = new Tree.AsyncTreeNode({
    text: 'Ext JS',
    draggable:false,
    id:'source'
  });
  tree.setRootNode(root);

  // render the tree
  tree.render();
  root.expand();
});




按照这个格式修改下