标签:
在学习的一个项目中,用到了zTree的插件,通过运用这个插件可以实现添加菜单的子栏目等功能,便于后台的管理,在一次性加载树列表的时候,在js中通过$post方式提交到后台action进行处理,在action方法中需要返回一个从表中查询出来的list,这时候使用JSONobject就不能够将list传到回调函数中了,因为JSONObject中不能够接受list类型参数,后来苦苦的调试当中发现,将list通过ActionContext.getContext().getValueStack().getRoot().push(list);方式放入值栈栈顶,在后台的回调函数中的data就直接可以拿到list数据,并且是不用通过data.list获取,这种方式在我看来好像很神奇的样子,当运行成功时,那么回调函数中就会直接去值栈中查找自己所需要的数据,这种查找直接从栈顶开始查起,所以放在栈顶的元素就直接会被读取,当然这也只是一种可能,具体的还要再做细究之后再来描述,上几段代码先吧:
public String getAllMenuitem() throws IOException{
System.out.println("通过getAllMenuitem");
this.menuitemlist = this.menuitemService.getAllMenuitem();
ActionContext.getContext().getValueStack().getRoot().push(menuitemlist);
return "success";
}
以下是js代码:
var tree = {
setting:{
isSimpleData: true,
treeNodeKey: "mid",
treeNodeParentKey: "pid",
showLine: true,
root:{
isRoot:true,
nodes:[]
},
callback:{
expand:function(){
alert("aaa");
}
}
},
/**
* 1、回调函数是由服务器端触发的,什么时候执行由服务器决定
* 2、回调函数是由jQuery内核调用的
* 3、客户端存在两个线程
* 4、如果在js代码中,有一些代码要用到回调函数中的数据,那么这些代码必须放在回调函数中
*/
loadTree:function(){
$.post("menuitem/Menuitem_getAllMenuitem.action",null,function(data){
alert(data);//可以读取数据
alert(data.menuitemlist);//没有定义
$("#tree").zTree(tree.setting,data);//加载树列表
});
}
};
$().ready(function(){
tree.loadTree();
});
,这个可以一次性加载树列表,
标签:
原文地址:http://www.cnblogs.com/AsherBlog/p/5474661.html