【问题标题】:Set select field options conditionally based on prior select field value根据先前的选择字段值有条件地设置选择字段选项
【发布时间】:2019-06-18 21:24:58
【问题描述】:

我以这些数据为例,但在 Keystone 中,有没有办法根据先前的选择字段设置选择字段的选项?

例如,如果我选择了一个州,那么在它之后的下一个选择中,它会要求输入城市,它会根据所选州填充城市的选项。

有没有一种方法可以编写 if...else 语句或某种方法来做到这一点,而无需为所有 50 个州创建一堆城市字段(oregonCities、washingtonCities、idahoCities 等)

类似这样的:

  state: {
    type: Types.Select,
    options: 'Oregon, Washington'
  },
  city: {
    type: Types.Select,

    //if state selected is oregon use these options
    dependsOn: { state: 'Oregon' },
    options: 'Portland, Bend, Salem'

    //if state selected is washington use these options
    dependsOn: { state: 'Washington' },
    options: 'Seattle, Olympia, Spokane'
  },

【问题讨论】:

    标签: keystonejs


    【解决方案1】:

    在当前版本中不可能,但您可以将此作为功能请求添加到 alpha 阶段的下一个版本。 github - https://github.com/keystonejs/keystone-5

    【讨论】:

    • 必须有一个解决方法——我目前正在做的是创建一堆城市字段(oregonCity、washingtonCity 等)然后使用dependsOn 显示它们,但这并不理想。另外,我认为他们想使用精明的功能请求。当前有一个功能请求打开:keystonejs.canny.io/feature-requests/p/…
    • 必须在管理 ui 代码中添加该解决方法,KeystoneJs v4 处于维护模式。不要指望那里有任何新功能
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-16
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多