我有一个表单提交的Ember组件,我暴露了几种不同的表单字段类型(在这种情况下,text-field
,checkbox-field
,等等),但是想要隐藏实现细节通过不公开实现每个字段的组件的名称(simple-form-field
)。我遇到的问题是组件需要传入一些变量,因此我需要为同一组件实现的每个表单字段重复参数传递。是否有一种干嘛的方法可以避免这样做?
在这里,您可以看到changeset=changeset
,disabled=disabled
和inline=inline
都重复了。
// templates/components/simple-form.hbs
{{#with (hash
text-field=(component 'form/simple-form-field'
control='control-text' changeset=changeset disabled=isDisabled inline=inline)
labeled-field=(component 'form/simple-form-field'
control='control-labeled' changeset=changeset disabled=isDisabled inline=inline)
dropdown-field=(component 'form/simple-form-field'
control='control-dropdown' changeset=changeset disabled=isDisabled inline=inline)
date-field=(component 'form/simple-form-field'
control='control-date' changeset=changeset disabled=isDisabled inline=inline)
daterange-field=(component 'form/simple-form-field'
control='control-daterange' changeset=changeset disabled=isDisabled inline=inline)
checkbox-field=(component 'form/simple-form-field'
control='control-checkbox' changeset=changeset disabled=isDisabled inline=inline)
submit-button=(component 'form/submit-button' disabled=(or changeset.isInvalid isDisabled)))
as |formFields|}}
{{yield formFields}}
{{/with}}