0 0

struts2 ext2 树!(online等)30

这是ext2.0的代码
  <script type="text/javascript">
		Ext.onReady(function(){
			var Tree = Ext.tree;
			
 	     	var tree = new Ext.tree.TreePanel({
			    el:'tree-div',
			    autoScroll : true,
            	animate : true,
	            enableDD : true,
    	        containerScroll : true,
	            loader : new Tree.TreeLoader({
                  dataUrl : 'initialize.action'
    	        })
			});
			
			var root = new Ext.tree.AsyncTreeNode({
				text:'ASK123',
				draggable : false,
		        id:'0000'
			});
			
			tree.setRootNode(root);
			
     		tree.render();

      		root.expand();
		});
		</script>


这是java代码
   public String execute() throws Exception {
		// ...
		list = moduleService.findBySjmkm(this.node);
		if(list != null && list.size() > 0){
		    boolean isFirst = true;
            int last = list.size();
            int count = 0;
            for (int i = 0; i < list.size(); i++) {
            	Module m = (Module) list.get(i);
            	 if (count == 0) {
                     this.setJsonString("[{\"text\" :\"" + m.getMc() + "\" ,\"id\" :\"" + m.getBh()
                                   + "\" ,\"cls\" :\"folder\"} ");
              } else if (i == (last - 1)) {
                     this.setJsonString(this.getJsonString() + ",{\"text\" :\"" + m.getMc() + "\" ,\"id\" :\""
                                   + m.getBh() + "\" ,\"cls\" :\"folder\"}]");
              } else {
                     this.setJsonString(this.getJsonString() + ",{\"text\" :\"" + m.getMc() + "\" ,\"id\" :\""
                                   + m.getBh() + "\" ,\"cls\" :\"folder\"}");
              }
            	count++;
			}
            System.out.println(this.getJsonString());
		}
		return SUCCESS;
	}

java代码里json我打出来是这个格式
[{"text" :"ALA管理" ,"id" :"5500" ,"cls" :"folder"} ,{"text" :"行销管理" ,"id" :"6100" ,"cls" :"folder"},{"text" :"财务管理" ,"id" :"7000" ,"cls" :"folder"},{"text" :"案件管理" ,"id" :"9000" ,"cls" :"folder"},{"text" :"系统" ,"id" :"1100" ,"cls" :"folder"},{"text" :"电子商务平台" ,"id" :"1300" ,"cls" :"folder"},{"text" :"会员管理" ,"id" :"3100" ,"cls" :"folder"},{"text" :"决策分析" ,"id" :"8010" ,"cls" :"folder"},{"text" :"协同办公平台" ,"id" :"8510" ,"cls" :"folder"},{"text" :"公开班管理" ,"id" :"1501" ,"cls" :"folder"},{"text" :"加盟商合作接口" ,"id" :"668471" ,"cls" :"folder"}]
======================================
现在问题是前台树只出来一个根节点,得不到后台的数据,但是我吧数据源dataUrl : 'initialize.action'换成一个txt文本,文本里面写action得到的json却可以!到手帮小弟解决一下啊!!
2008年5月24日 11:15

5个答案 按时间排序 按投票排序

0 0

用jsonplugin吧,这样就不用再写烦人的那些json字符串了

2008年6月05日 13:00
0 0

你用firebug看一下传过来的数据格式对麽

2008年6月04日 15:52
0 0

大哥 你用console打印有什么用
System.out.println(this.getJsonString());  

应该是printwriter打印

前台才会拿得到

2008年6月04日 14:15
0 0

在服务器上debug,看看这段js 到底请求的是什么url,有些时候相对路径会造成这个错误
you want:
myhost.com/init.action

but it request:

myhost.com/yourcurrentlocation/init.action

2008年5月28日 16:48
0 0

# loader : new Tree.TreeLoader({ 
#                 dataUrl : 'initialize.action' 
#             }) 

直觉告诉我,问题出在这

2008年5月28日 16:43

相关推荐

Global site tag (gtag.js) - Google Analytics