简体   繁体   中英

Pass argument to event handler in Ember handlebars helper

I'd like to reuse the same action for focusing an input field in and out, passing it eg true or false as an argument, instead of writing two actions. I can't work out how to pass arguments in, though; is it possible?

Eg {{input focus-in="toggleSomething true" focus-out="toggleSomething false"}} is how I expected it might work, but no.

Unfortunately you can't pass an argument in like that, the only parameter passed through to the action is the current value of the text field.

You can see this if you look at the source for the focusIn function, which calls the local sendAction function that in turn calls Ember.Component.sendAction passing in the "value" variable.

Not sure if this is the correct use for this but I managed to pass argument values through to the action like this -

{{input focus-in=(action "toggleSomething" true) focus-out=(action "toggleSomething" false)}}

I am using Ember 1.13.0

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