我有一个名为 reservations.js 的 js 文件,在这个文件中我有一个预订数组,例如:
var reservations = [
{ "HotelId": "01", "HotelName": "SPA", "ReservNum": "0166977", "Guest Name": "Jonny", "Room": null, "Type": "SUIT", "Rooms": "1", "Board": "BB", "Status": "IH", "Pax": "2,0,0,0", "Arrival": "07/08/12", "Departure": "09/08/12", "AgentDesc": "FIT", "AgentCode": "FIT", "Group": null, "Balance": "0", "Requests": "", "Remarks": null, "Fit/Group": "FIT", "ReturnGuestName": "", "StatusColor": "LightCoral" },
{ "HotelId": "01", "HotelName": "SPA", "ReservNum": "H000192", "Guest Name": null, "Room": null, "Type": "Folio", "Rooms": "0", "Board": "", "Status": "IH", "Pax": "0,0,0,0", "Arrival": "07/08/12", "Departure": "10/09/12", "AgentDesc": "movies", "AgentCode": "001", "Group": null, "Balance": "0", "Requests": "", "Remarks": "", "Fit/Group": "FIT", "ReturnGuestName": "", "StatusColor": "LightCoral" }
];
我需要做的是创建一个包含 6 个列的表(在 html 中):Res。号码、客人姓名、状态、到达日期、离开日期、房间类型。并将数组中的元素插入到表中匹配的 col 中。
示例:ReservNum": "0166977",因此数字 0166977 将在第一列 Res. Number 中。
我的桌子是这样的:
<table id="reservations">
<thead>
<tr>
<th>Res. Number</th><th>Guest Name</th><th>Status</th><th>Arrival Date</th><th>Departure Date</th><th>Room Type</th>
</tr>
</thead>
<tbody>
<tr>
<td>resnum</td><td>guestname</td><td>status</td><td>arrivaldate</td><td>departuredate</td><td>roomtype</td>
</tr>
</tbody>
</table>
我不知道该怎么做。我试图在 js 文件中做这样的事情:
$('#reservations tr').each(function (i) {
$(this).find('td').html(reservations[i]);
});
但它不起作用。(也许我的 html 表是错误的或者是 js,甚至两者都有)。
我是 js/jquery 的新手,所以我有点不确定自己在做什么。