如何在Reaction Commerce中将<select>输入添加到product variantForm中?

时间:2016-09-27 09:21:43

标签: meteor meteor-autoform

如何获得&lt; select&gt;产品varientForm中的下拉菜单? 我们在这里看到的东西:

1 个答案:

答案 0 :(得分:1)

要完成添加&lt; select&gt;如上所示,我们需要编辑或扩展三个文件,variantForm.html,variantForm.js和products.js模式: 反应/进口/插件/包括/产品变/客户/模板/产品/产品详情/变形/ variantForm / variantForm.html 反应/进口/插件/包括/产品变/客户/模板/产品/产品详情/变形/ variantForm / variantForm.js 反应/ LIB /集合/模式/ products.js 在&lt; select&gt;的AutoForm实例中我们看到一个如下所示的架构: {   typeTest:{     type:String,     可选:true,     autoform:{       输入:“选择”,       options:function(){         返回[           {label:“2013”​​,价值:2013},           {label:“2014”,价值:2014},           {label:“2015”,价值:2015}         ]。       }     }   } } 和Blaze模板HTML,如下所示: {{#autoForm id =“types2”schema = typesSchema2}}   {{&GT; afFormGroup name =“typeTest”type =“select”options = optionsHelper}}   &lt; div class =“form-group”&gt;     &lt; button type =“submit”class =“btn btn-primary”&gt;提交&lt; / button&gt;   &LT; / DIV&GT; {{/ AUTOFORM}} 步骤1 编辑/扩展products.js模式文件添加您的选择,除了我们只需要添加这些部分: typeTest:{   type:String,   可选:true,   autoform:{     类型:“选择”   } }, Reaction Commerce忽略AutoForm中的optionHelper函数,如上例所示。我保持autoform:{type:“select”}只是为了表达内涵。有关以这种方式修改的product.js架构的真实示例,请参见此处。 第2步 将您的辅助函数添加到variantForm.js,它返回您的选择的选项对象。在Template.variantForm.helpers({})里面添加: variantTypeOptions:function(){   返回[     {label:“默认”,价值:2013},     {标签:“身高和体重”,价值:“身高和体重”}   ]。 }, 很好很简单(和AutoForm示例类似),这些成为我们在上面的屏幕截图中看到的选择选项。现实世界的例子。 第3步 最后一步。让我们最后将Blaze模板HTML添加到variantForm.html: &lt; div class =“form-group {{#if if afFieldIsInvalid name ='variantType'}} has-error {{/ if}}”&gt;   &lt; label class =“control-label”&gt; {{afFieldLabelText name ='variantType'}}&lt; / label&gt;   {{&gt; afFieldInput name ='variantType'type =“select”options = variantTypeOptions}}   {{#if afFieldIsInvalid name ='variantType'}}     &lt; span class =“help-block”&gt; {{afFieldMessage name ='variantType'}}&lt; / span&gt;   {{/如果}} &LT; / DIV&GT; 我们专注于: {{&gt; afFieldInput name ='variantType'type =“select”options = variantTypeOptions}} 现实世界的例子。 闭幕致辞 您可能需要执行rc重置才能使模式的更改生效,但是警告,这将擦除您的本地开发数据库。请参阅RC Docs中有关必须在“创建插件”文章中进行频繁重置的说明。
相关问题