简体   繁体   中英

Ember yield multiple actions into component

I have a checkout-form component which has some actions like next , previous , submitForm and selectDate . Currently I'm only able to yield the selectDate action like this:

{{!-- checkout-form.js --}}
<div class='checkout-form'>
  {{yield (action 'selectDate')}}
</div>

I'd like to be able to use my checkout-form component like this:

{{!-- 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}}

How would I go about yielding multiple actions to be used inside of my checkout-form.hbs ?

option 1. You can pass many arguments like below

{{yield (action 'selectDate') (action 'submitForm')}}

Read - https://guides.emberjs.com/v2.14.0/components/block-params/

and

{{!-- order.hbs --}}
{{#checkout-form as |selectDate, submitForm|}} 
  {{checkout-form-actions action=selectDate}}
  {{checkout-form-actions action=submitForm}}
{{/checkout-form}}

option 2. You can also use hash helper ,

{{yield (hash 
        selectDate=(action 'selectDate')
        submitForm=(action 'submitForm')) }}

and

{{#checkout-form as |options|}}   
  {{checkout-form-actions action=options.submitForm}}
{{/checkout-form}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM