javascript中遍歷物件的List集合
阿新 • • 發佈:2019-02-01
<script>
<c:forEach var="obj" items="${mulst} ">
alert("${obj.屬性}");
</c:forEach>
</script>
其實該解決方案不是很好,容易導致瀏覽器崩潰,當List元素很多時,迴圈的程式碼就很多,頁面很龐大,瀏覽器吃不消!另外, 服務端生成的資料,客戶端去遍歷的問題,最好使用Ajax技術。
- $.ajax({
- type: 'post',
- url: "maintain_findRoomByBuildingId.shtml",
- cache: false
- data: {"buildingId":buildingId},
- dataType: 'json',
- success: function(data){
- jQuery.each(data.roomList, function(i,item){
- alert(item.id+","+item.name);
- });
- },
- error: function(){
- return;
- }
- });