思路
实战
var roomdetaildata;
$.ajax({
url:"http://localhost:8080/room/selectRoomMiniServiceByHotelId?hotelId="+hotelId,
type:"GET",
success:function (result2) {
roomdetaildata = result2;
}
});
var mydata = [] ;
$(function () {
var policyitems = $("#policy-items");
// console.log(policyitems);
$.ajax({
url:"http://localhost:8080/room/selectRoomByHotelId?hotelId="+hotelId,
type:"GET",
success:function (data) {
var list = [];
for (var i = 0; i < data.data.length; i++) {
// mydata.add(data.data[i].roomId);
mydata.push(data.data[i].roomId)
var ni = i;
list.push("<p class=\"name\" title=\""+data.data[i].hotelRoomName+"\">"+data.data[i].hotelRoomName+"</p>");
list.push("<span>面积"+data.data[i].hotelRoomArea+"㎡</span>");
//这里不能再用ajax,必须调用之前的
for (var k = 0; k < roomdetaildata.data.length; k++) {
if (roomdetaildata.data[k].roomId == mydata[i]) {
var breakfast;
var iswindow;
if (roomdetaildata.data[k].isBreakfast == false){
breakfast = '无早餐';
} else {
breakfast = '有早餐'
}
if (roomdetaildata.data[k].isWindow == false) {
iswindow = '无窗';
} else {
iswindow = '有窗';
}
var lessprice = roomdetaildata.data[k].roomOriginPrice - roomdetaildata.data[k].roomPrice;
list.push("<span class=\"name\" title=\""+data.data[i].hotelRoomName+"\">"+data.data[i].hotelRoomName+"</span>");
list.push("<dd class=\"policy-price\"><span>¥</span><span>"+roomdetaildata.data[k].roomPrice+"</span></dd>");
list.push("<span class=\"minuPrice\">原"+roomdetaildata.data[k].roomOriginPrice+"返"+lessprice+"</span>");
}
}
}
policyitems.html(list.join(""));
}
}
转载:https://blog.csdn.net/qq_36436290/article/details/101305292
查看评论