我正在研究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'}.
这里有一个国家及其州。但问题是如何改变国家选择的状态下拉。我想在更改国家/地区下拉列表时更改州选择选项。我是通过观察这个领域来尝试的,但它并不起作用。有什么建议/方向吗?
答案 0 :(得分:0)
使用文档中字段的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管理界面中,只有state
等于country
时才会向用户显示Pakistan
字段。该字段仍可由您的代码设置,但无法通过UI(Web浏览器)进行设置。