音乐厅座位计划的数据结构

时间:2017-03-15 18:19:09

标签: javascript mongodb data-structures database

我正在努力开发一个音乐会座位预订系统,我想用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的{​​{1}}对象,每个对象都有多个对象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' },
          ]
        }
      ]
    }
  ]
}

这会有用吗?

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

1 个答案:

答案 0 :(得分:1)

我会做这样的事情:

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"
}