最近在用jQuery就在网上找了个树js来用,发现easyui所以就配置一下使用,下载了论坛上的一个离线doc文档谁知道那个文档的属性不全,easyui属性只写了两个(url和animate),那就用吧,可是问题来了,struts2返回的json数据格式是key:value型的怎么转啊,找了半天,后来在一个问题贴上看到有一个data属性晕,上官方网站看了下.
url | string | a URL to retrive remote data. | null |
animate | boolean | Defines if to show animation effect when node expand or collapse. | false |
checkbox | boolean | Defines if to show the checkbox before every node. | false |
cascadeCheck | boolea | Defines if to cascade check. | true |
onlyLeafCheck | boolean | Defines if to show the checkbox only before leaf node. | false |
data | array | The node data to be loaded. | null |
里面有一个data属性就是需要传入的node data.
后台类
package com.eversun.delivery.web.action.site; import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.annotation.Resource; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONArray; import org.apache.struts2.interceptor.ServletRequestAware; import org.apache.struts2.interceptor.ServletResponseAware; import org.apache.struts2.json.annotations.JSON; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; import com.eversun.delivery.database.ISiteManager; import com.opensymphony.xwork2.ActionSupport; @Controller @Scope("prototype") public class FindSiteTreeAction extends ActionSupport implements ServletResponseAware { @Resource private ISiteManager siteManager; private HttpServletResponse response; //字符串返回 private String treeJsonStr; //开始我使用的ArrayList传递过去可是怎么也出不来数据改成string了. //后来用这个试验也可以 private JSONArray jsonList ; @JSON(serialize = false) public String getTreeList() { //这句话不用理会就是返回一个jsonarray就行 JSONArray jsonArray = (JSONArray)siteManager.getTreeJsonData(siteManager .getProvinceAndSiteRoot()); this.setJsonList(jsonArray); this.setTreeJsonStr(jsonArray.toString()); return SUCCESS; } public void setServletResponse(HttpServletResponse response) { this.response = response; } public String getTreeJsonStr() { return treeJsonStr; } public void setTreeJsonStr(String treeJsonStr) { this.treeJsonStr = treeJsonStr; } public JSONArray getJsonList() { return jsonList; } public void setJsonList(JSONArray jsonList) { this.jsonList = jsonList; } }
?前台代码
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <html> <head> <style> .layoutstyle{ height:100%; width:100%; display:block; } </style> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>网点管理</title> <link rel="stylesheet" type="text/css" href="../../css/easyui.css"> <script type="text/javascript" src="../../js/common/jquery.js"></script> <script type="text/javascript" src="../../js/easyui/jquery.easyui.min.js"></script> <script type="text/javascript"> jQuery(function(){ $.getJSON("getSiteTreeAction.action", function(json){ //alert(json.jsonList.length); //string 的需要这样转一下由于data的数据类型是array的. var strjson = eval('('+json.treeJsonStr+')'); //alert(strjson.jsonList.length); $('#typetree').tree({ checkbox: false, //这里需要注意一下data一共可以传两种方式的数据第一种被我注释掉了 //data:json.jsonList, data:strjson, onClick:function(node){ $(this).tree('toggle', node.target); alert('you dbclick '+node.attributes.type); } }); }); }); function reload(){ $('#typetree').tree('reload'); } </script> </head> <body > <div class="easyui-layout layoutstyle" > <div region="east" split="true" title="网点类别" style="width:150px;"> <ul id="typetree"> </ul> </div> <div id="content" region="center" title="网点列表" style="padding:5px;"> </div> </div> </body> </html>?
1 楼
okwang1979
2010-09-06
版本
query-1.4.2.min.js
jquery.easyui 1.2
query-1.4.2.min.js
jquery.easyui 1.2
2 楼
wei_jiyong
2012-03-19
有没有这个例子的源代码,给我发一份,我最近正在做这一块的项目,急需,谢谢!邮箱是252637867@qq.com
3 楼
wmmang
2012-05-25
看了你的文章我终于弄出来了。真心感谢!
4 楼
tomfish88
2012-06-01
{"jsona":[{"total":"a","total2":"a2"}]} 我生成的数据是这个样子的,无法解析怎么,
能不能直接生成[{"total":"a","total2":"a2"}] 这个样子的呢
能不能直接生成[{"total":"a","total2":"a2"}] 这个样子的呢
5 楼
tomfish88
2012-06-07
jsonarray的格式是什么样的? 能列一个么? 如:
[{
"id":"001",
"text":"Languages",
"state":"open",
"children":[{
"id":"99",
"text":"Java1"
},{
"id":"88",
"text":"C#",
"children":[{
"id":"888",
"text":"C#1"
},{
"id":"887",
"text":"C#2"
}]
}]
}]
[{
"id":"001",
"text":"Languages",
"state":"open",
"children":[{
"id":"99",
"text":"Java1"
},{
"id":"88",
"text":"C#",
"children":[{
"id":"888",
"text":"C#1"
},{
"id":"887",
"text":"C#2"
}]
}]
}]
6 楼
tomfish88
2012-06-07
最终还是用你的方法搞定了3q