查询条件:
<table style=" 100%;border-collapse: collapse;" > <tr> <th style=" 15%;">分 类:</th> <td style=" 35%"> <input id="source_detail" name="source_detail" class="zxui-combotree"> </td> <th style=" 15%;">任务状态:</th> <td style=" 35%"> <input type="radio" name="z-status" id="z-all" checked="" value=''>全部 <input type="radio" name="z-status" id="z-normal" value='1'>正常 <input type="radio" name="z-status" id="z-pro-overdue" value='2'>可能超期 <input type="radio" name="z-status" id="z-overdue" value='3'>超期 </td> </tr> <tr> <th>名 称:</th> <td colspan="3"> <input id="serchname" class="zxui-textbox" style=" 80%;"> <a href="javascript:search()" class="zxui-linkbutton" data-options="iconCls:'icon-search'" style="80px;line-height:22px;">筛 选</a> </td> </tr> </table>
ajax:
(注意:在js中以var定义变量,赋值给另一变量作为条件是的以用语法 “ ‘+var+’ ”
例如:
‘<img title="" class="light" src=" '+msgid+' "/>’
因为ajax返回json不能直接写入到table中去,需要判断转换为url路径放入到table中的图片中去,我先对json值做了判断,根据值的不同,给msgid赋值不同,再写入图片标签的src中去,
因为语法问题在这里饶了好长时间。在一变量的形式给html解析页面时,变量里的html标签用“”引起来,颜色为蓝色,如果便签内出现了“”是要转译的,否则报错。
)
function search(mygz,acceptoridif,acceptorid){ var code =$("#source_detail").combotree("getValue"); var title =$("#serchname").val(); var waring = $("input[name='z-status']:checked").val(); var taskid = $().val; $.ajax({ type : "post", url : "${ctx}/control/first_Like.pt", data : {code:code,waring:waring,title:title,mygz:mygz,acceptoridif:acceptoridif,acceptorid:acceptorid}, success : function(json){ $('#biaodan tr:gt(0)').remove();//删除之前的数据 for (var i = 0; i < 10; i++){ var msgid ; if (json.list[i].waring == 3) { msgid = '${res}/img/red.png'; }else if (json.list[i].waring == 2) { msgid = '${res}/img/yellow.png'; }else { msgid = '${res}/img/green.png'; } var titlet = ""; if(json.list[i].readid == null){ titlet = "<td class='z-fontColorBlue'>"+ "<a href="javascript:diaban('"+json.list[i].taskid +"','"+json.list[i].nodeid +"','"+json.list[i].ywid +"','"+json.list[i].lb +"','"+json.list[i].departflag +"','"+json.list[i].lastparentid +"' ,'"+json.list[i].lastparent +"' )">" +"<span>"+json.list[i].title +"</span>"+"<img style="height:1.2em; 1.6em;display:inline-block;border:none" src="${res}/img/firstnew.gif" />"+"</a></td>"; }else{ titlet = titlet = "<td class='z-fontColorBlue'>"+ "<a href="javascript:diaban('"+json.list[i].taskid +"','"+json.list[i].nodeid +"','"+json.list[i].ywid +"','"+json.list[i].lb +"','"+json.list[i].departflag +"','"+json.list[i].lastparentid +"' ,'"+json.list[i].lastparent +"' )">" +json.list[i].title+"</a></td>"; } var tr="<tr class='bg'><td>"+(i+1)+"</td>" /* +"<td>"+ json.list[i].lbstr +"</td>" */ +"<td>"+ json.list[i].code +"</td>" + titlet +"<td>"+ json.list[i].acceptor +"</td>" +"<td>"+ "<img class='light' src='" +msgid+ "'/></td>" +"<td>"+ json.list[i].percents +"</td>"; var gzstr = ""; if(json.list[i].gz_id == null){ gzstr = "<td>"+"<button id='"+json.list[i].taskid+"' onclick="guanzhu('"+json.list[i].taskid+"');return false;" >关注</button></td></tr>"; }else{ gzstr = "<td>"+"<button id='"+json.list[i].taskid+"' onclick="qxguanzhu('"+json.list[i].gz_id+"','"+json.list[i].taskid+"');return false;">"+"<span style='color:red;'>★</span>已关注</buton>"+"</td>"; } tr += gzstr; $('#biaodan').append(tr); } } }); }
java后台:
@RequestMapping("/first_Like") @ResponseBody public void ajax_generateCode(@RequestParam("code") String code, @RequestParam("waring") String waring, @RequestParam("title") String title) throws IOException { Dmp dmp = this.getParamsAsDmp(); System.out.println(code+waring+title); UserInfo user = getUserInfo(); String userid = user.getUserid(); dmp.put("userid", userid); dmp.put("code", code); dmp.put("waring",waring); dmp.put("title", title); List list = serv.select_first_lingdaorwcx(dmp); System.out.println(list.size()); Dmp jsonmap=new BaseDmp(); if(list!=null && list.size()>0){ jsonmap.put("list", list); } String jsonstr=jsonmap.toJson(); this.writeResponse(jsonstr,"json"); }