刺激JS控制器
如何在页面加载上调用刺激控制器功能? 这是我在刺激控制器中的功能:
hide(event)
{
$(this.testTargets[0].tpggle(event.currentTarget.checked);
}
How do I call a stimulus controller function on page load?
Here is my function in stimulus controller:
hide(event)
{
$(this.testTargets[0].tpggle(event.currentTarget.checked);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无法通过您给出的内容来判断该名称是什么,但是连接功能会在加载上调用。
评论后编辑
好吧,因为我不知道您的HTML或您的刺激控制器是什么样的。我要猜测。
我在一行上看到复选框,因此我假设您有一个要在页面加载上检查的复选框。我假设您的HTML看起来像这样:
只是一个具有5个目标的复选框的页面。
要检查第一个,它只是:
但是我还假设您将使用复选框做其他事情。也许隐藏/显示一个元素。我不知道您将要做什么,但是如果您确实想在页面上隐藏/显示元素,那将是这样的,并且您有一个我们要切换的类 hidden :
和扩展的控制器:
希望这能让您入门。掌握刺激术语需要一些时间。
Can't tell what that name is by what you've given, but the connect function will call on load.
EDIT after comment
Okay, since I do not know what your html or your stimulus controller looks like. I'm going to guess.
I see checkbox on one line so I'm going to assume you have a checkbox that you want to check on page load. I'll assume your html looks something like this:
Just a page with 5 checkboxes that are targets.
To check the first one, its just:
But I'll also assume you are going to do something else with the checkboxes. Maybe hide/show an element. I have no idea what you are going to do, but if you did want to hide/show element on the page it would be something like this and you have a class hidden that we are going to toggle:
and the expanded controller:
Hope this gets you started. It takes a little time to get the hang of stimulus terminology.
尝试一下我的家伙! W状态管理的痛苦
刺激之所以很棒,是因为它确实可以减轻终端中
:在App/JavaScript/Controllers/Checkbox_controller.js中
,在App/Javascript/Controllers/Moruty_checkboxes_controller.js中
,最终在您的视图中:
祝您好运!
Try this out my dude! Stimulus is great because it really relieves the pains that come w state management
in terminal:
in app/javascript/controllers/checkbox_controller.js
in app/javascript/controllers/multiple_checkboxes_controller.js
And finally this in your view:
Good luck!