nojave 2009-08-31 15:37
浏览 320
已采纳

0分也能提问么?(实在没分了)Ext Tree 叶节点展开不了

按照sample尝试实现一个动态树,由action直接打印出String,然后在页面根据String构成树.
结果可以显示树的根节点和一级节点,但是在打开二级节点的时候失败.一直在loading...
并出现错误: Object expected.
虽然是0分,还是希望各位大大帮忙看下.
action直接打印的String如下:
[code="java"]
[
{id: 1,text: '1111111',leaf: true},
{id: 2,text: '222222',children: [{id: 21,text: '2333333',leaf: true}]}
]
[/code]
js code:
[code="java"]
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 : 'loadusertree.action'
    })

});

// set the root node
var root = new Tree.AsyncTreeNode({
    text : 'Ext JS',
    draggable : false,
    id : 'src'

});
tree.setRootNode(root);

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

// tree.expandAll();
});

[/code]
[b]问题补充:[/b]
感谢两位,直接打印出来的String就是上面那个,而且只是在展开2级节点时出问题,估计是出在children那里,就是找不到.纳闷ing.
atian25 大大,
'tree2.json' 该怎么跟我action返回的String联系起来呢?
[b]问题补充:[/b]
struts.xml
[code="xml"]
method="getUserListByGrp">
/usertree.jsp
/error.jsp

[/code]

getUserListByGrp:
[code="java"]
public String getUserListByGrp() {
try {
String tempstring = "[{id: 1,text: '1111111',leaf: true},"
+ "{id: 2,text: '222222',children: ["
+ "{id: 21,text: '2333333',leaf: true}]" + "}]";
System.out.println(tempstring);
ActionContext ctx = ActionContext.getContext();
HttpServletRequest request = (HttpServletRequest) ctx
.get(ServletActionContext.HTTP_REQUEST);
HttpServletResponse response = (HttpServletResponse) ctx
.get(ServletActionContext.HTTP_RESPONSE);
response.reset();
response.setCharacterEncoding("utf-8");
response.setContentType("text/xml");
PrintWriter writer = response.getWriter();
writer.print(tempstring);
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
return SUCCESS;
}
[/code]

[b]问题补充:[/b]
感谢!
不过现在我又发现问题了,
"struts2不是这么返回json数据的",那应该是怎么返回呢?我以前试Grid时,用writer.write(jsonstring); 将数据直接打印回给请求页面,Grid是可以接收到action返回的格式化后的String的.
另外,难道一定要使用jsonlib么?jsonlib的作用不只是帮我们格式化String么?如果我已经把String格式化成json的格式,我是不是将这个String直接返回就好了呢?http://www.blogjava.net/usherlight/archive/2008/02/19/180590.html 中,它返回的"menuString" 不也是"private String menuString;"么?
我的理解是jsonstring在action看来,其实也就是一String,只是Ext处理的时候,它会将这条有格式的jsonstring解析成不同的对象或者数组,等等,不知道这种理解有无问题.
[b]问题补充:[/b]
晕,firefox下能正确展开所有节点,firebug中看报到String如下班:
[code="java"]
[{id: 1,text: '1111111',leaf: true},{id: 2,text: '222222',children: [{id: 21,text: '2333333',leaf: true
}]}]
[/code]
看来是要找找IE7的问题了.
[b]问题补充:[/b]
IE 7下直接访问action得到:
[code="java"]
[
{id: 1,text: '1111111',leaf: true},
{id: 2,text: '222222',children:
[{id: 21,text: '2333333',leaf: true}]}
]
[/code]
伴随着错误信息:
"Invalid at the top level of the document. Error processing resource 'http://localhost:8080/prodinfo/loadusertree.action'."
不过这个错误似乎是不是XML解析错误,应该跟我这问题无关吧.
[b]问题补充:[/b]
感谢!
action里面已经有response.setContentType("text/xml");

用右键盘查看loadusertree.action源文件一样得到:
[{id: 1,text: '1111111',leaf: true},{id: 2,text: '222222',children: [{id: 21,text: '2333333',leaf: true}]}]
很奇怪啊.
[b]问题补充:[/b]
改为dataUrl : 'tree.json'后还是展不开2级节点. 源文件已上传了.
[b]问题补充:[/b]
感谢atian25 兄,我先研究下.
[b]问题补充:[/b]
唉,还是有问题,发现问题有碍文章写"IE下不能够使用TreeLoader加载树",莫非是这个问题?
[b]问题补充:[/b]
非常感谢atian25兄,问题已解决,似乎 是Ext包的问题,可能是3.0升级时不完整,我用你的Ext包替换我的之后,问题解决,再次感谢!等下结贴.

  • 写回答

15条回答 默认 最新

  • iteye_10013 2009-09-01 11:55
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(14条)

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题