javascript获得json对象的map.
javascript获得json对象的map.//json返回的mapvarmap=json.userMap;map里存的是list,如何遍历循环呢?可得到KEY....
javascript获得json对象的map.
//json返回的map
var map = json.userMap;
map里存的是list,如何遍历循环呢?
可得到KEY. 展开
//json返回的map
var map = json.userMap;
map里存的是list,如何遍历循环呢?
可得到KEY. 展开
展开全部
遍历js对象
for (var index in data) {
//data表示js对象, index是key, data[index]是值
}
for (var index in data) {
//data表示js对象, index是key, data[index]是值
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
ajax 返回类型 有多种 json 跟 text是常用的 text 返回一般是一层就可以了 所以一般就是 data.表达名 json两层了就
json.put("states", jsonMembers2);
json.put("user", jsonMembers1);
一个json 可以返回多个类型数据了吧
到了前台呢 就可以根据不同json属性名来取数据了
后台:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
PrintWriter out=response.getWriter();
String startTime=request.getParameter("date1");
String endTime=request.getParameter("date2");
int dept_id=Integer.parseInt(request.getParameter("dept"));
List<Dept> dailys=dep.deptDailyQuery(startTime, endTime, dept_id);
List<Dept> users=dep.deptuserQuery(dept_id);
JSONObject json=new JSONObject();
JSONArray jsonMembers = new JSONArray();
System.out.println(dailys.size());
JSONArray jsonMembers2 = new JSONArray();
JSONObject member2 = new JSONObject();
JSONObject member3 = new JSONObject();
if(dailys.size()==0){
member2.put("state", 0);
jsonMembers2.put(member2);
json.put("states", jsonMembers2);
}
if(dailys.size()!=0){
member2.put("state", 1);
member2.put("state", 2);
jsonMembers2.put(member2);
member3.put("state", 1);
member3.put("state", 2);
jsonMembers2.put(member3);
json.put("states", jsonMembers2);
for(Dept daily:dailys){
JSONObject member = new JSONObject();
member.put("date", daily.getDaily_date());
member.put("name", daily.getUser_name());
member.put("id", daily.getUser_id());
jsonMembers.put(member);
}
json.put("city", jsonMembers);
JSONArray jsonMembers1 = new JSONArray();
for(Dept user:users){
JSONObject member1 = new JSONObject();
member1.put("user_id",user.getUser_id());
member1.put("user_name", user.getUser_name());
jsonMembers1.put(member1);
}
json.put("user", jsonMembers1);
}
out.print(json);
return null;
}
}
前台:
success:function(data){
if(data.states.length==1){
alert("NO ONE HAS WRITE DAILY");
}else{
$('#t').remove();
var startDatestr=$('#daily_date_begin').val();
var startstr=startDatestr.replace(/-/g,"/");
var endDatestr=$("#daily_date_end").val();
var endstr=endDatestr.replace(/-/g,"/");
var count=(new Date(endstr)-new Date(startstr))/(24*3600*1000);
var array_name=new Array(count+1);
var arr=new Array();
var arr_name=new Array();
arr.push("@@@@");
for(var i=0;i<data.user.length;i++){
arr.push(data.user[i].user_id);
arr_name.push(data.user[i].user_name);
}
var allitems=arr_name.length;
var nowpage=cui;
var pagesize=10;
var allpage=Math.ceil(1.0 * allitems /pagesize);
var startrow=(nowpage-1)*pagesize;
var endrow=nowpage*pagesize;
if(endrow>=allitems){
endrow=allitems;
}
var str='<table id="t" class="title" border="1">';
str=str+'<tr style="background: #DAF0F0"><th>---</th>';
for(var x=0;x<=count;x++){
var da=new Date(startstr);
var days=new Date(da.getTime()+x*24*3600*1000);
str=str+'<th>'+days.getYear()+'-'+(days.getMonth()+1)+'-'+days.getDate()+'</th>';
}
str=str+'</tr>';
str=str+'<tr style="background: #DAF0F0"><th>姓名</th>';
for(var x=0;x<=count;x++){
var da=new Date(startstr);
var days=new Date(da.getTime()+x*24*3600*1000);
var m="";
看着点就明白了:for(var i=0;i<data.user.length;i++){
arr.push(data.user[i].user_id);
arr_name.push(data.user[i].user_name);
}
if(data.states.length==1){
alert("NO ONE HAS WRITE DAILY");
}else{
}
json.put("states", jsonMembers2);
json.put("user", jsonMembers1);
一个json 可以返回多个类型数据了吧
到了前台呢 就可以根据不同json属性名来取数据了
后台:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
PrintWriter out=response.getWriter();
String startTime=request.getParameter("date1");
String endTime=request.getParameter("date2");
int dept_id=Integer.parseInt(request.getParameter("dept"));
List<Dept> dailys=dep.deptDailyQuery(startTime, endTime, dept_id);
List<Dept> users=dep.deptuserQuery(dept_id);
JSONObject json=new JSONObject();
JSONArray jsonMembers = new JSONArray();
System.out.println(dailys.size());
JSONArray jsonMembers2 = new JSONArray();
JSONObject member2 = new JSONObject();
JSONObject member3 = new JSONObject();
if(dailys.size()==0){
member2.put("state", 0);
jsonMembers2.put(member2);
json.put("states", jsonMembers2);
}
if(dailys.size()!=0){
member2.put("state", 1);
member2.put("state", 2);
jsonMembers2.put(member2);
member3.put("state", 1);
member3.put("state", 2);
jsonMembers2.put(member3);
json.put("states", jsonMembers2);
for(Dept daily:dailys){
JSONObject member = new JSONObject();
member.put("date", daily.getDaily_date());
member.put("name", daily.getUser_name());
member.put("id", daily.getUser_id());
jsonMembers.put(member);
}
json.put("city", jsonMembers);
JSONArray jsonMembers1 = new JSONArray();
for(Dept user:users){
JSONObject member1 = new JSONObject();
member1.put("user_id",user.getUser_id());
member1.put("user_name", user.getUser_name());
jsonMembers1.put(member1);
}
json.put("user", jsonMembers1);
}
out.print(json);
return null;
}
}
前台:
success:function(data){
if(data.states.length==1){
alert("NO ONE HAS WRITE DAILY");
}else{
$('#t').remove();
var startDatestr=$('#daily_date_begin').val();
var startstr=startDatestr.replace(/-/g,"/");
var endDatestr=$("#daily_date_end").val();
var endstr=endDatestr.replace(/-/g,"/");
var count=(new Date(endstr)-new Date(startstr))/(24*3600*1000);
var array_name=new Array(count+1);
var arr=new Array();
var arr_name=new Array();
arr.push("@@@@");
for(var i=0;i<data.user.length;i++){
arr.push(data.user[i].user_id);
arr_name.push(data.user[i].user_name);
}
var allitems=arr_name.length;
var nowpage=cui;
var pagesize=10;
var allpage=Math.ceil(1.0 * allitems /pagesize);
var startrow=(nowpage-1)*pagesize;
var endrow=nowpage*pagesize;
if(endrow>=allitems){
endrow=allitems;
}
var str='<table id="t" class="title" border="1">';
str=str+'<tr style="background: #DAF0F0"><th>---</th>';
for(var x=0;x<=count;x++){
var da=new Date(startstr);
var days=new Date(da.getTime()+x*24*3600*1000);
str=str+'<th>'+days.getYear()+'-'+(days.getMonth()+1)+'-'+days.getDate()+'</th>';
}
str=str+'</tr>';
str=str+'<tr style="background: #DAF0F0"><th>姓名</th>';
for(var x=0;x<=count;x++){
var da=new Date(startstr);
var days=new Date(da.getTime()+x*24*3600*1000);
var m="";
看着点就明白了:for(var i=0;i<data.user.length;i++){
arr.push(data.user[i].user_id);
arr_name.push(data.user[i].user_name);
}
if(data.states.length==1){
alert("NO ONE HAS WRITE DAILY");
}else{
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你直接在你的方法里面把list查询出来,然后在js中 直接for循环data.list.length就能可以了,有什么不明白的继续问哈
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2012-03-05
展开全部
用for in循环呗。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询