如何使一个领域取决于其他领域的价值meteorautoform?

我是meteor的新手,我想创build一个表单,其中一个字段的值决定了autoform中另一个字段的值 。 让我们把安装types设置为“A”,“B”和“C”,所以当我select“A”时,autoform将被加载。 我已经把这个表格作为通用的,即它将显示给所有A,B和C.

{{#each users}} {{> afQuickField name='userEmail' value=userEmail readOnly=true }} {{> afQuickField name='Setup' value=type readOnly=true}} {{> afQuickField name='Profile' options='allowed' }} {{> afQuickField name='Purpose' }} {{> afQuickField name='count' options='allowed' }} {{> afQuickField name='PackageDirectory' options='allowed' }} {{> afQuickField name="logName" options=LogName }} {{/each}} 

计数选项应该是:
1.对于“A”计数选项应该是9,11,12。
2.“B”是1。
3.“C”是5。
在架构中,我写了这样的代码

 Setup:{ type: String, label:"Setup", optional:false, defaultValue:type }, count:{ type: String, label:"No. Of count", optional: true, allowedValues:["9","11","12"], autoform:{ afFieldInput:{ firstOption:"(Select the count)" } } } 

所以当我select安装“A”我应该得到三个下拉选项,当我点击“B”和“C”我应该得到默认值分别为1和5。 任何人都可以解决我的问题?

您可以使用getFieldValue获取特定字段的值,并基于该值从模板助手中返回一组optiondefaultValue 。 文档在这里find

所以按照你的代码:

form.html:

  ... {{#autoForm id="sampleFormID" ... ... }} {{> afQuickField name='Setup' value=type readOnly=true}} {{> afQuickField name='count' options=allowedOptionHelper defaultValue=defaultValueHelper }} ... {{/autoForm}} 

form.js

 Template.templateName.helpers({ allowedOptionsHelper: function() { if (AutoForm.getFieldValue('Setup', 'sampleFormID') === 'A') { return [{label:"9", value:"9"},{label:"11",value:"11"},{label:"12", value:"12"}]; else if (AutoForm.getFieldValue('Setup', 'sampleFormID') === 'B') { // return the options for B } else if (AutoForm.getFieldValue('Setup', 'sampleFormID') === 'C')) { // return the options for C } }, defaultValueHelper: function() { if (AutoForm.getFieldValue('Setup', 'sampleFormID') === 'A') { return 11 //or whatever the defaultValue is; } //likewise for options B and C } }); 

schema.js

 ... ... count:{ type: String, label:"No. Of count", optional: true, autoform:{ afFieldInput:{ firstOption:"(Select the count)" } } } ... ...