jquery easyui tree动态加载-服务端struts返回json数据
json
适用于现代 C++ 的 JSON。
项目地址:https://gitcode.com/gh_mirrors/js/json

·
第一种方法:
js:
<script type="text/javascript">
$(function() {
$(document).ready(function() {
$.post("./test/tree.action", {}, function(json) {
$("#tt").tree({
data : json.itemsList,
onClick : function(node) {
$.post("./test/tree.action", {
"id" : node.id
}, function(json) {
$('#tt').tree('append', {
parent : node.target,
data : json.data
});
}, "json");
}
});
}, "json");
});
});
</script>
</head>
<body>
<ul id="tt"></ul>
</body>
struts:
action:
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.struts2.json.annotations.JSON;
import com.opensymphony.xwork2.ActionSupport;
public class TreeAction extends ActionSupport {
private List<Map<String, Object>> itemsList;
private int id;
@Override
public String execute() throws Exception {
itemsList = new ArrayList<Map<String, Object>>();
for (int i = 0; i < 5; i++) {
Map<String, Object> item = new HashMap<String, Object>();
item.put("id", i);
item.put("text", i);
item.put("state", "closed");
// item.put("children", itemsList2);
itemsList.add(item);
}
return super.execute();
}
@JSON(serialize = true, name = "data")
public List<Map<String, Object>> getItemsList() {
return itemsList;
}
public void setItemsList(List<Map<String, Object>> itemsList) {
this.itemsList = itemsList;
}
}
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="test" extends="json-default" namespace="/test">
<action name="tree"
class="com.test.struts.TreeAction">
<result name="success" type="json"></result>
</action>
</package>
</struts>
第二种方法:
js:
<script type="text/javascript">
$(function() {
$(document).ready(function() {
$("#tt2").tree({
url : "test/tree.action"
});
});
});
</script>
</head>
<body>
<ul id="tt2"></ul>
</body>
struts:
public class TreeAction extends ActionSupport {
private int id;
@Override
public String execute() throws Exception {
//可根据id查找相应节点
itemsList = new ArrayList<Map<String, Object>>();
for (int i = 0; i < 5; i++) {
Map<String, Object> item = new HashMap<String, Object>();
item.put("id", i);
item.put("text", i);
item.put("state", "closed");
// item.put("children", itemsList2);
itemsList.add(item);
}
String data = JSONUtils.toJson(itemsList).toString();
ServletActionContext.getResponse().getWriter().write(data);
return null;
}
//getter
//setter
}




适用于现代 C++ 的 JSON。
最近提交(Master分支:4 个月前 )
f06604fc
* :page_facing_up: bump the copyright years
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* :page_facing_up: bump the copyright years
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* :page_facing_up: bump the copyright years
Signed-off-by: Niels Lohmann <niels.lohmann@gmail.com>
---------
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
Signed-off-by: Niels Lohmann <niels.lohmann@gmail.com> 1 个月前
d23291ba
* add a ci step for Json_Diagnostic_Positions
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* Update ci.cmake to address review comments
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* address review comment
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix typo in the comment
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix typos in ci.cmake
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* invoke the new ci step from ubuntu.yml
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* issue4561 - use diagnostic positions for exceptions
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix ci_test_documentation check
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* address review comments
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix ci check failures for unit-diagnostic-postions.cpp
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* improvements based on review comments
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix const correctness string
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* further refinements based on reviews
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* add one more test case for full coverage
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* ci check fix - add const
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* add unit tests for json_diagnostic_postions only
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix ci_test_diagnostics
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix ci_test_build_documentation check
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
---------
Signed-off-by: Harinath Nampally <harinath922@gmail.com> 1 个月前
更多推荐
所有评论(0)