Ajax異步請求,對map中的list集合進行遍歷

resp爲一個Map對象,包含有一個List集合,經過jQuery.each(resp.cmpList, function(i,item){ }對List集合進行遍歷,resp.cmpList爲一個list集合,item爲list集合裏的一個元素 html

$.ajax(
	{
		url:'/data/query_media',
		cache: false,
		type:'post',
		data:paramStr,
		dataType:'json',
		async:false,
		success:function(resp)
		{
			$("#con_one_2").children().hide();
			$("#con_one_2").append("<div id='media_"+resp.pageIndex+"'></div>")
			//$("#con_one_2").empty();
			//遍歷公司集合,拼接顯示公司列表
			 jQuery.each(resp.proList, function(i,item){  
			 	 $("#media_"+resp.pageIndex).append("<div class=\"ttkx\">"+
            	 "<div class=\"tp\"><div><a href=\"/get_media_info.html?id="+item.id+"\"><img src=\""+item.cover+"\" width='114' height='90' /></a></div></div> "+
             	 " <div class=\"tp_z\">"+
            	 "  <p><b>簡介:</b>"+ checkNull(item.productExplain)+"</p>"+
             	 " <p><b>價格:</b>"+ price(checkNull(item.productPrice))+"</p>"+
            	 "  <p><b>類型:</b>"+ checkNull(item.productType)+"</p>"+
            	 "  <p><b>公司:</b><a href='/get_company_info.html?cmpId="+item.cmpId+"'>"+ item.cmpName+"</a></p>"+
           		 " </div>"+
          		 "</div>");
              
            }); 
            //設置分頁
            var page1 = "";
            var page2 = "";
            var next = parseInt(resp.pageIndex)+1;
            var pre = parseInt(resp.pageIndex)-1
            if(resp.pageIndex>1)
            {
            	page1 = "<td><a onclick='nextPageMedia("+pre+");'><img src=\"/images/Previous_page.jpg\" width=\"59\" height=\"25\" style='cursor:pointer'/></a></td>";
            }else{
            	page1 = "<td><img src=\"/images/Previous_page.jpg\" width=\"59\" height=\"25\" /></td>"
            }
             if(parseInt(resp.pageIndex) < parseInt(resp.maxPage))
            {
            	page2 = "<td><a onclick='nextPageMedia("+next+");'><img src=\"/images/next_page.jpg\" width=\"59\" height=\"25\" style='cursor:pointer'/></a></td>";
            }else{
            	page2 = "<td><img src=\"/images/next_page.jpg\" width=\"59\" height=\"25\" /></td>"
            }
            
            $("#media_"+resp.pageIndex).append("<table cellpadding=\"0\" cellspacing=\"0\" id=\"page\">"+
            "<tr>"+
            "<td >&nbsp;</td>"+
            page1+
             "<td >&nbsp;"+resp.pageIndex+"/"+resp.maxPage+"</td>"+
           page2+
            "</tr>"+
            "</table>");	
		}
	});
相關文章
相關標籤/搜索