public String querySTDMeasureTree() {
HttpServletResponse response = ServletActionContext.getResponse();
STDMeasureBean[] beans = entityMeasureService
.getSTDMeasureList(stdMeasureBean);
if (beans != null) {
PrintWriter out = null;
response.setContentType("text/html;charset=GBK");
try {
out = response.getWriter();
} catch (IOException e) {
e.printStackTrace();
}
String sReturn = "";
sReturn += "{'ResultSet':{'Result':[";
for (int i = 0; i < beans.length; i++) {
sReturn += "{'name':'" + beans[i].getName() + "','id':'"
+ beans[i].getId() + "'},";
}
sReturn = sReturn.substring(0, sReturn.length() - 1) + "]}}";
logger.debug(sReturn);
out.write(sReturn);
out.flush();
out.close();
}
return null;
}
前台:
<link rel="stylesheet" href="<%=path%>/css/demo.css" type="text/css">
<link rel="stylesheet" href="<%=path%>/css/zTreeStyle/zTreeStyle.css" type="text/css">
<script type="text/javascript" src="<%=path%>/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="<%=path%>/js/jquery.ztree.core-3.1.js"></script>
<!-- <script type="text/javascript" src="<%=path%>/js/jquery.ztree.excheck-3.1.js"></script>-->
<script type="text/javascript" src="<%=path%>/js/jquery.ztree.exedit-3.1.js"></script>
<script type="text/javascript">
<!--
var setting = {
async: {
enable: true,
url:"<%=path%>/querySTDMeasureTree.action",
autoParam:["id", "name"],
otherParam:{"id":"name"},
dataFilter: filter
}
};
function filter(treeId, parentNode, childNodes) {
if (!childNodes) return null;
for (var i=0, l=childNodes.length; i<l; i++) {
childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
}
return childNodes;
}
$(document).ready(function(){
$.fn.zTree.init($("#treeDemo"), setting);
});
//-->
</SCRIPT>
<title> ZTREE DEMO - single path</title>
</head>
<body>
<h1>异步加载节点数据的树</h1>
<h6>[ 文件路径: core/async.html ]</h6>
<div class="content_wrap">
<div class="zTreeDemoBackground left">
<ul id="treeDemo" class="ztree"></ul>
</div>
</div>
</body>
</html>
哪出错了吗 ?? 为什么没有数据显示啊???? 今天刚学的,请各位前辈多多指教!!!
1 个解决方案
#1
请务必区分 JSON 格式的字符串 和 JSON 数据对象。 zTree 使用的是 JSON 数据对象,不是 JSON 格式的字符串。
____举例:
______(1)JSON 格式的字符串: var nodes = "[{id:1, name:'test1'}, {id:2, name:'test2'} ]";
______(2)JSON 数据对象: var nodes = [{id:1, name:'test1'}, {id:2, name:'test2'} ];
____举例:
______(1)JSON 格式的字符串: var nodes = "[{id:1, name:'test1'}, {id:2, name:'test2'} ]";
______(2)JSON 数据对象: var nodes = [{id:1, name:'test1'}, {id:2, name:'test2'} ];
#1
请务必区分 JSON 格式的字符串 和 JSON 数据对象。 zTree 使用的是 JSON 数据对象,不是 JSON 格式的字符串。
____举例:
______(1)JSON 格式的字符串: var nodes = "[{id:1, name:'test1'}, {id:2, name:'test2'} ]";
______(2)JSON 数据对象: var nodes = [{id:1, name:'test1'}, {id:2, name:'test2'} ];
____举例:
______(1)JSON 格式的字符串: var nodes = "[{id:1, name:'test1'}, {id:2, name:'test2'} ]";
______(2)JSON 数据对象: var nodes = [{id:1, name:'test1'}, {id:2, name:'test2'} ];