后台java从数据库获取数据组装:
public void queryNextLevel() {
//System.out.println("*******************************a");
int level = this.organizationService.queryOrgLevel(orgCode);
if (level == 50) {
this.result = this.organizationService.queryAllUser(orgCode);
} else
this.result = this.organizationService.queryNextLevel(orgCode);//组装
System.out.println("*******************************" + this.result);
// System.out.println(result);
try {
JsonUtil.sendJsonString(result);//送前台
} catch (IOException e) {
e.printStackTrace();
}
}
-----------------------------------------------------------------------------------------------------------------------------
public String queryNextLevel(String orgCode) {
List
List
if (orgs != null && orgs.size() > 0) {
for (Organization org : orgs) {
OrgCounty item = new OrgCounty();
item.setOrgCode(org.getOrgCode());
if(org.getOrgLevel()==50){
item.setOrgName(org.getOrgName());
}else{
item.setOrgName(org.getOrgNameSimple());
}
item.setLatitude(org.getLatitude());
item.setLongitude(org.getLongitude());
result.add(item);
}
}
JSONArray jsonObj = JSONArray.fromObject(result);
String returnVal = jsonObj.toString();
System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&" + returnVal);
return returnVal;
}
组装结果输出:&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&[{"latitude":302520590000,"longitude":1201902880000,"orgCode":"31006100","orgLevel":0,"orgName":"杭州","superOrgCode":""},{"latitude":301766350000,"longitude":1202995090000,"orgCode":"31126100","orgLevel":0,"orgName":"萧山","superOrgCode":""},{"latitude":298053610000,"longitude":1196801720000,"orgCode":"31156100","orgLevel":0,"orgName":"桐庐","superOrgCode":""},{"latitude":300532350000,"longitude":1199430430000,"orgCode":"31146100","orgLevel":0,"orgName":"富阳","superOrgCode":""},{"latitude":302325510000,"longitude":1197256760000,"orgCode":"31136100","orgLevel":0,"orgName":"临安","superOrgCode":""},{"latitude":304183510000,"longitude":1203035780000,"orgCode":"31116100","orgLevel":0,"orgName":"余杭","superOrgCode":""},{"latitude":294809430000,"longitude":1192879850000,"orgCode":"31166100","orgLevel":0,"orgName":"建德","superOrgCode":""},{"latitude":296006780000,"longitude":1190605880000,"orgCode":"31176100","orgLevel":0,"orgName":"淳安","superOrgCode":""}]
--------------------------------------------------------------------------------------------------------------------------------------------------------------
送前台java:
public static void sendJsonString(String content) throws IOException {
if (content == null) {
content = "";
}
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("UTF-8");
response.setContentType("text/plain");
response.getWriter().write(content);
}
-----------------------------------------------------------------------------------------------------------------------------
前台js处理:
function bindEvenForSelect(selectId,url,nextSelect,orgCode){
$("#"+selectId).bind("change",function(evt){
initNextOrginaztion(selectId);
var selectedOrgCode = $(this).val();
//alert(url);
if(selectedOrgCode != "-1"){
$.ajax({
url:url,
tyee:"POST",
dataType:"json",
cache:false,
data:"orgCode="+selectedOrgCode,
success:function(r){
// else{
if($("#"+nextSelect).find("option").eq(0).val() != -1 ){
$("#"+nextSelect).append('');
}
for(var i=0;i
$("#"+nextSelect).append('');
}
},
error:function(){
alert("AJAX请求失败");
}
});
}
});
}