我有一个checkout-form
组件,其中包含next
,previous
,submitForm
和selectDate
等操作。目前,我只能yield
selectDate
这样的行动:
{{!-- checkout-form.js --}}
<div class='checkout-form'>
{{yield (action 'selectDate')}}
</div>
我希望能够像我这样使用我的checkout-form
组件:
{{!-- order.hbs --}}
{{#checkout-form as |submitForm, selectDate|}}
{{checkout-field placeholder="Full Name" value=model.order.name}}
{{!-- another field component that uses selectDate --}}
{{checkout-form-actions action=submitForm}}
{{/checkout-form}}
如何在我的checkout-form.hbs
内部使用多个动作?
答案 0 :(得分:4)
选项1。您可以传递多个参数,如下所示
{{yield (action 'selectDate') (action 'submitForm')}}
阅读 - https://guides.emberjs.com/v2.14.0/components/block-params/
和
{{!-- order.hbs --}}
{{#checkout-form as |selectDate, submitForm|}}
{{checkout-form-actions action=selectDate}}
{{checkout-form-actions action=submitForm}}
{{/checkout-form}}
选项2。您还可以使用hash helper,
{{yield (hash
selectDate=(action 'selectDate')
submitForm=(action 'submitForm')) }}
和
{{#checkout-form as |options|}}
{{checkout-form-actions action=options.submitForm}}
{{/checkout-form}}