我正在尝试遍历这个 JSON 来创建一个表。JSON 中有 3 个元素,即席位、行数和席位价格。每个 td 需要有一个基于行的 id 以及沿行的距离(即,每个数字 1 是一个座位,因此需要将计数添加到它们)。它还必须将 pricelookup 数据添加为一个类,以便单击的座位可以有不同的价格。
var data = {
"who": "RSNO",
"what": "An American Festival",
"when": "2013-02-08 19:30",
"where": "User Hall - Main Auditorium",
"seats": [
"00000000000000000011111111111111000000000000000000",
"0000000000000001111111111111111aaa0000000000000000",
"00000000000000aa111111111111111aaaaa00000000000000",
"00000000000001111111111111111111111111000000000000",
"000000000aa00aaaaaaaaaaaaaaaaaaaaaa1100aa000000000",
"00000001111001111111111111111111111100111100000000",
"00000aaaaaa0011aaaaaaaaa11111111aaa1100aaaaaa00000",
"00001111111001111111111111111111111100111111100000",
"000aaaaaaa110011111111111111111111110011aaaaaaa000",
"00111111111100111111111111111111111001111111111000",
"00aaaaa1111110011111111111111111111001111aaaaaaa00",
"11111111111100111111111111111111111001111111111110",
"0aaaaaaaaaaaa001111111111111111111100aaaaaaaaaaaa0",
"01111111111110011111111111111111110011111111111100",
"00000000000000001111111111111111110000000000000000",
"01111111111111001111111111111111100111111111111100",
"01111111111111001111111111111111110011111111111110",
"01111111111111001111111111111111100111111111111100",
"00a11111111111100111111111111111100111111111111a00",
"00111111111111100111111111111111001111111111111000",
"00011111111111110011111111111111001111111111111000",
"00111111111111100111111111111111001111111111111000",
"00011111111111110011111111111111001111111111111000",
"00011111111111110011111111111110011111111111110000",
"0000000111a111111001111a1111a110011111111110000000",
"00000000111111110011111111111110011111111000000000",
"00000000001111111001111111111110011111110000000000",
"00000000000000111001111111111100111000000000000000"
],
"rows": [
"DD",
"CC",
"BB",
"AA",
"Z",
"Y",
"X",
"W",
"V",
"U",
"T",
"S",
"R",
"Q",
"P",
"N",
"M",
"L",
"K",
"J",
"H",
"G",
"F",
"E",
"D",
"C",
"B",
"A"
],
"seatPrice": [
" 00000000000000 ",
" 0000000000000000000 ",
" 0000000000000000000000 ",
" 0000000000000000000000000 ",
" 00 000000000000000000000000 00 ",
" 0000 00000000000000000000000 0000 ",
" 000000 000000000000000000000000 000000 ",
" 0000000 00000000000000000000000 0000000 ",
" 000000000 0000000000000000000000 000000000 ",
" 0000000000 000000000000000000000 0000000000 ",
" 00000000000 00000000000000000000 00000000000 ",
"000000000000 000000000000000000000 000000000000 ",
" 000000000000 00000000000000000000 000000000000 ",
" 000000000000 0000000000000000000 000000000000 ",
" 000000000000000000 ",
" 0000000000000 00000000000000000 0000000000000 ",
" 0000000000000 000000000000000000 0000000000000 ",
" 0000000000000 00000000000000000 0000000000000 ",
" 0000000000000 0000000000000000 0000000000000 ",
" 0000000000000 000000000000000 0000000000000 ",
" 0000000000000 00000000000000 0000000000000 ",
" 0000000000000 000000000000000 0000000000000 ",
" 0000000000000 00000000000000 0000000000000 ",
" 0000000000000 0011111111100 0000000000000 ",
" 0000000000 111111111111 0000000000 ",
" 00000000 1111111111111 00000000 ",
" 0000000 111111111111 0000000 ",
" 000 00000000000 000 "
],
"priceLookup": [
10,
20
]
}
$(data.seats).each(function (index, element) {
$('#plan').append('<tr><td> ' + element[0] + ' </td></tr>');
})
到目前为止,它只创建了第一列,只创建了座位布局,而不是其他数据。任何帮助,将不胜感激。我的主要问题是试图让它同时适用于行和列。