六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 36|回复: 0

jquery操作map

[复制链接]

升级  40%

4

主题

4

主题

4

主题

童生

Rank: 1

积分
20
 楼主| 发表于 2013-1-26 13:46:40 | 显示全部楼层 |阅读模式
File类:
int       fileId;
String  filePath;
 
get、set方法略。。。
 
服务端FileManageAction.java:
Map map=new HashMap();
map.put("fileList", bizDao.getFileList());
String json=JSONArray.fromObject(map).toString();
log.info("json:"+json);
   
response.setHeader("Content-Type", "text/html; charset=GBK");
response.getWriter().write(json);
 
log.info打印结果:
[{"fileList":[{"fileId":2995,"filePath":"a.jsp"},
{"fileId":2990,"filePath":"b.jsp"},
{"fileId":2997,"filePath":"c.jsp"}]}]
 
页面:
var url="<%=request.getContextPath()%>/fileManage.do";
$.getJSON(url,
    function(data){
        $.each(data[0],function(key,values){
        if(key=='fileList'){
         $("#fileContent").append("<p>文件信息:</p>");
         $(values).each(function(iex,item){
          $("#fileContent").append("<p style='word-wrap:break-word'>文件路径:"+item.filePath+"</p><br>");
         });
         $("#fileContent").append("<hr>");
        }
       });
   }
  );
 
最终fileContent div展现:
文件信息:
文件路径:a.jsp
文件路径:b.jsp
文件路径:c.jsp
 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表