我正在研究keystone。我陷入了一个问题,我们有两个依赖于另一个的字段。
country: {type: Types.Select, required: true, initial: true, options: 'Pakistan'},
state: {type: Types.Select, required: true, initial: true, label: 'State/Province', options: 'Punjab, Sindh'}.
这里有一个国家及其州。但问题是如何改变国家选择的状态下拉。我想在更改国家/地区下拉列表时更改州选择选项。我通过观看该领域尝试但它不起作用。有什么建议/方向吗?
使用文档中字段的dependsOn
属性。
http://keystonejs.com/docs/database/#fields-conditional
country: { type: Types.Select, required: true, initial: true, options: 'Pakistan'},
state: { type: Types.Select, required: true, initial: true, dependsOn: { country: 'Pakistan' }, label: 'State/Province', options: 'Punjab, Sindh'}.
您可以将以下内容添加到您的字段中:
dependsOn: { country: 'Pakistan' }
在Keystone Admin UI中,如果state
等于country
,则Pakistan
字段仅显示给用户。该字段仍可由您的代码设置,但无法通过UI(Web浏览器)进行设置。