Netlify CMS - 如何通过config.yml集合存储对象数组

问题描述 投票:1回答:1

我对Netlify的CMS有点困惑 - 特别是在通过config.yml定义架构时。我正在使用Netlify CMS和Gatsby静态站点,以允许最终用户更新网站上的一些动态数据。

我想要实现的目标:

我想在CMS上使用数据类型以允许用户创建新的旅行日期,具有最大占用率和当前占用率(即,在所述旅行中当前预订了多少人)。

为了达到这个目的,我目前已经使用了这个config.yml(这个config.yml位于我的Gatsby项目的static/admin w.r.t项目根目录):

backend:
  name: git-gateway
  branch: master

publish_mode: editorial_workflow

media_folder: src/images/uploads
public_folder: /uploads

collections:
  - name: "tourInfo"
    label: "Tour Info"
    description: "Upcoming tours and their availability"
    files:
      - label: "tour"
        name: "Tour"
        file: "static/tours.json"
        fields:
          - {label: "Tour Date", name: "date", widget: "datetime"}
          - {label: "Total Places", name: "totalPlaces", widget: "number"}
          - {label: "Filled Places", name: "filledPlaces", widget: "number"}

这似乎不是我想要的,我似乎无法创建大量的巡演日期,但只有一个。在集合类型方面,这可能是对我的一个基本误解,但我认为我可以将tour定义为单个文件,然后用大量的游览实例填充它。

有人能指出我如何在没有文件死亡的情况下实现这一系列的旅游数据点的正确方向吗?

gatsby netlify netlify-cms
1个回答
1
投票

您可以将该集合设为folder collection或使用list widget

使用list的示例,包含您的代码:

collections:
  - name: "tourInfo"
    label: "Tour Info"
    description: "Upcoming tours and their availability"
    files:
      - label: "tour"
        name: "Tour"
        file: "static/tours.json"
        fields:
          - label: "Tour List"
            name: "tourList"
            widget: "list"
            fields:
              - {label: "Tour Date", name: "date", widget: "datetime"}
              - {label: "Total Places", name: "totalPlaces", widget: "number"}
              - {label: "Filled Places", name: "filledPlaces", widget: "number"}

因此,您的旅行日期,地点等可以放在列表的fields下。对于大量数据来说,它看起来非常难以驾驭,但您可能希望使用自定义widet对其进行分页,或使用文件夹集合。

© www.soinside.com 2019 - 2024. All rights reserved.