javascript中遍历对象的List集合

来源:互联网 发布:三菱fx2nplc仿真软件 编辑:程序博客网 时间:2024/05/18 00:34

<script>
<c:forEach var="obj" items="${mulst} "> 
alert("${obj.属性}"); 
</c:forEach> 
</script>


其实该解决方案不是很好,容易导致浏览器崩溃,当List元素很多时,循环的代码就很多,页面很庞大,浏览器吃不消!
另外,
服务端生成的数据,客户端去遍历的问题,最好使用Ajax技术。
  1. $.ajax({  
  2.         type: 'post',  
  3.         url: "maintain_findRoomByBuildingId.shtml",  
  4.         cache: false,  
  5.         data: {"buildingId":buildingId},  
  6.         dataType: 'json',  
  7.         success: function(data){  
  8.             jQuery.each(data.roomList, function(i,item){  
  9.                 alert(item.id+","+item.name);  
  10.             });  
  11.         },  
  12.         error: function(){  
  13.             return;  
  14.         }  
  15.     }); 

0 0
原创粉丝点击