【问题标题】:keystonejs display select option depending on choosing another select optionkeystonejs 显示选择选项取决于选择另一个选择选项
【发布时间】:2017-11-02 02:05:27
【问题描述】:

我正在 keystone.js 应用程序模型中尝试从选择选项中选择与用户在另一个选择选项中选择的内容相关的内容.. 所以他会从第一个中选择,第二个选择选项应该只有与第一个选择的选项相关的数据.. 我希望有一个人可以帮助我 非常感谢

【问题讨论】:

    标签: node.js keystonejs


    【解决方案1】:

    你应该使用dependsOn选项。

    例子..

    type: { type: Types.Select, options: ['TypeOne','TypeTwo','TypeThree TypeFour' ], initial: true },
    
    something: { type: Types.Text, dependsOn: { type: 'TypeThree' }, initial: true },
    

    关系示例 - 您可以按照逻辑显示某些字段仅在依赖条件匹配时才会显示。

    Adjustment.add({
    type: { type: Types.Select, options: ['Booking','Shipment','Warehouse','Inventory' ], initial: true },
    sku: { type: Types.Text, initial: true },
    quantity: { type: Types.Number, initial: true, width: 'short' },
    keyID: { type: Types.Relationship, ref: 'Order', dependsOn: { type: 'Booking' }, initial: true },
    bookingID: { type: Types.Relationship, ref: 'Booking', dependsOn: { type: 'Booking' }, initial: true },
    warehouse: { type: Types.Relationship, ref: 'Warehouse', dependsOn: { type: 'Warehouse' }, initial: true },
    shipmentID: { type: Types.Text, dependsOn: { type: 'Shipment' }, initial: true },
    

    });

    【讨论】:

    • 但我正在尝试通过使用 Types:relationships 和对模型的引用来使选项变得动态......这是我面临的技巧
    • 我更新了我的原始答案,以包含一个与关系一起使用的示例。
    • 选项数据是否可能来自数据库?
    猜你喜欢
    • 2021-01-20
    • 2018-08-17
    • 1970-01-01
    • 2011-06-13
    • 1970-01-01
    • 2019-12-22
    • 1970-01-01
    • 1970-01-01
    • 2020-05-13
    相关资源
    最近更新 更多