为什么使用 JsHelper 进行 jQuery 集成?
我试图集成 jQuery 以在我的网站中使用它来实现一些效果,并且我开始寻找以最佳方式集成的解决方案。我只是想到编写一个助手来获取正确元素的选择器并输出 javascript 代码。 然后我在 cake 1.3 中遇到了新的 JsHelper,但我在理解 JsHelper 的概念时确实遇到了问题。我的意思是,我要编写的每个 JavaScript 块肯定不止一次调用 jQuery 方法,并且其中许多方法也不会传输到 JsHelper。那么我可以使用 JsHelper 的原因是什么?在助手中编写为我的操作指定的 javascript 并像任何其他助手一样使用它会更容易。我认为唯一好的功能就是使用 JsHelper 中提供的缓存和缓冲选项。我是否很好地理解了 JsHelper 还是我遗漏了一些要点?
I was trying to integrate jQuery to use it for some effects in my site and I started to search for the solution of integrating in the best way. It simply came to my mind to write a helper which would get the selector of proper element and output the javascript code.
Then I ran into the new JsHelper in cake 1.3 but I'm really having problems understanding the concept of JsHelper. I mean for sure each JavaScript block that I'm gonna write is more than one call to jQuery methods and many of them are also not transfered to JsHelper. So for what reason may I use the JsHelper? it would be much easier to write the javascript specified for my action inside a helper and use it simply as any other helper. The only thing which comes to my mind as a good capability is to use the caching and buffering options provided in JsHelper nothing more. Did I understood the JsHelper well or I have missed some points?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
FWIW,除了编写包含内容之外,我从不使用任何 javascript 帮助程序,即
link('aJavascriptFile') ?>
我会拉扯我的头发尝试找出为什么某些 jQuery 插件无法工作(如果它全部包含在助手中)。
您不必使用助手 - 他们会为您提供帮助。有时,人们会变得有点疯狂,开始为那些确实无法证明额外代码的重要性的东西创建助手。
只需用“旧方式”编写代码并保持理智即可。
FWIW, I never use any of the javascript helpers except to write the include, i.e.
<?php echo $javascript->link('aJavascriptFile') ?>
I'd be pulling my hair out trying to find out why some jQuery plugin wasn't working if it was all wrapped up in helpers.
You don't have to use helpers - they're there to help. Sometimes people go a bit crazy and start creating helpers for stuff that really doesn't justify the weight of extra code.
Just code it the 'old way' and keep your sanity.