-
Notifications
You must be signed in to change notification settings - Fork 423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to pass arguments through actions? #64
Comments
<div data-action="jump" data-slide-index="0">Open First slide</div> jump(event) {
const element = event.target
this.targets.findAll('slides')[element.dataset.slideIndex]
// next your logic to switch slides
} |
You could also write it like this jump(_event, element) {
this.targets.findAll('slides')[element.dataset.slideIndex]
// next your logic to switch slides
}``` |
Those are both reasonable options. Action methods are essentially just event handlers and there isn't a way to pass additional arguments to them. |
Im having some issues with the example provided by @adrianholovaty. This jsbin shows the issues: http://jsbin.com/xiyuho/edit?html,js,console,output |
@askehansen about safari if you look at the properties of |
Use |
Stimulus is the crap then, no ? |
I'm just playing with something like
After change "target" to "currentTarget" all fine. Is not is the crap ? PS. Thanks to this topic |
No.
|
Argument. Thanks, was not right. |
I have idea, all not understanding is about not passing DOM element to handler (I think it is common case). |
What I want - defined behavior of my code. |
For the slideshow example:
If I wanted to "jump" to the second image and would like to implement a "jump" action, I need to pass in the index of the clicked image. How can this be done?
The text was updated successfully, but these errors were encountered: