jquery的ajax 处理后台传来json格式的二维数组

@SuppressWarnings("unchecked")
@Path("getUsers.html")
@POST
@Produces({ MediaType.APPLICATION_JSON })
public Map getUserByName(MultivaluedMap<String, String> formParams) throws Exception {
String name=formParams.getFirst("name");
String project_id=formParams.getFirst("part_id");
List Users=null;
List<Part> parts=null;
users= jpaTemplate.find("select usp.user,usp.part.id as bid from USP usp where usp.user.name like '"+"%"+name+"%'");
parts= jpaTemplate.find("select usp.part from USP usp where usp.part.id='"+part_id+"'");
Map map=new HashMap();
map.put("users", users);
map.put("parts", parts);
return map;
}



<script type="text/javascript">
function cleanVal(){
document.getElementById('name').value="";
}
function setDefault(){
var value=document.getElementById('name').value;
if(value=="" || value==null){
document.getElementById('name').value="请输入姓名";
}
}

$(document).ready(function(){
$("#search").click(function(){
$.ajax({
url:"../../app/userManage/getUsers.html",
type:"POST",
data:$("#searchCondition").serialize(),
dataType:"json",
success:function(data){
try{
var html=' ';
$.each(data.users,function(i,item){
html += '<tr><td>'+ item[0].name +'</td><td>'+ item[0].sex+'</td><td>'+ item[0].addr +'</td>';
if(item[1]==" " || item[1] == null){

html += '<td>'+"未分配"+'</td></tr>';
}else{
$.each(data.parts,function(entryIndex,entry){
if(item[1]==entry.id){
html += '<td><a href="../userManage/to-user-detail.html?part_id='+entry.id+'&user_id=${user.id}" rel="external">'+entry.name+'</a></td></tr>';
return false;
}
});

}

return true;

});
$("#puser").html(html);
}catch(e){
alert("查询员工出现异常");
return;
}
},
error:function(result,status){
if(status == 'error'){
alert(status);
}
}
});
});
});
</script>


<form id="searchCondition" rel="external" data-ajax="false" enctype1="multipart/form-data">
<input name="part_id" type="hidden" value="${part.id}" />
<table width="90%" border="0" cellpadding="0" cellspacing="0"
style="margin: 4px">
<tr style="border: 0">
<td style="border: 0">
<label>搜索员工属于哪个部门:</label>
</td>
<td style="border: 0">
<input id="name" name="name" type="search" οnfοcus="cleanVal()" οnblur="setDefault()" value="请输入姓名" style="width: 100%" />
</td>
<td style="width: 1px; border: 0">
<input id="search" type="button" value="搜索" />
</td>
</tr>
</table>
</form>

<h3>员工属于哪个部门</h3>
<table id="title" >
<thead class="ui-bar-b">
<tr>
<th>姓名</th>
<th>性别</th>
<th>地址</th>
<th>所在部门</th>
</tr>
</thead>
<tbody id="puser">
</tbody>
</table>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值