gpt4 book ai didi

javascript - 音乐厅座位表的数据结构

转载 作者:行者123 更新时间:2023-12-03 04:47:15 25 4
gpt4 key购买 nike

我正在尝试开发一个音乐会座位预订系统,我想用 HTML、CSS 和 JavaScript 绘制座位。

如果音乐厅只有10排,每排20个座位,我可以得到的座位

const rows = [
{ name: 'A', seats: [1, 2, 3, 4] },
{ name: 'B', seats: [1, 2, 3, 4, 5, 6, 7, 8] },
{ name: 'C', seats: [1, 2, 3, 4] },
{ name: 'D', seats: [1, 2, 3, 4] },
];

但是如果音乐厅有多个部分怎么办?它仍然只是一个物体吗ConcertHall具有多个对象 Section ,每个对象都有多个对象 Row ,同样有多个座位 Seat

音乐厅看起来就像这样

{
name: "Concert Hall Name",
sections: [
{
name: "Balcon",
rows: [
{
name: "A",
seats: [1, 2, 3, 4, 5]
}
]
}
]
}

但我希望用户预订特定座位的机票,所以我想座位应该是一个独立的对象。也许类似

{
name: "Concert Hall Name",
sections: [
{
name: "Balcon",
rows: [
{
name: "A",
seats: [
{ id: 'some seat id', name: '1' },
{ id: 'some different seat id', name: '2' },
]
}
]
}
]
}

然后创建票证

{
date: 'some date',
seatId: 'some seat id'
}

这行得通吗?

它是否可以扩展到音乐厅,例如 http://www.lcsd.gov.hk/en/hkcc/common/images/facilities/concerthall/concert_hall_seating_plan_s.gif 的音乐厅?

最佳答案

我会做这样的事情:

const concertHall = {
"name": "Example Hall",
"seats": [
{
"id": 1,
"section": "1",
"row": "A",
"number": 42
},
{
"id": 2,
"section": "VIP Box 1",
"row": null,
"number": 1
},
{
"id": 3,
"section": "VIP Box 2",
"row": null,
"number": 1
},
{
"id": 4,
"section": "Wheelchair Box",
"row": null,
"number": 1
}
]
}

保持非常简单,每个座位都有您需要的所有信息。

然后,对于一张票,也许会是这样的:

{
"purchased": "2017-03-15T18:30:31.980Z",
"seatId": 1,
"holder": {
"firstName": "John",
"lastName": "Doe",
"email": "jdoe@example.com"
},
"eventId": 52,
"price": 102.42,
"currency": "USD"
}

关于javascript - 音乐厅座位表的数据结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42817703/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com