このファイルには、次のような予約の配列があります。
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. 番号、ゲスト名、ステータス、到着日、出発日、部屋タイプ。配列の要素をテーブル内の一致する列に挿入します。
例: 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が初めてなので、自分が何をしているのか少しわかりません。