问题描述
turbolinks (5.0.0)
导轨 4.2.2
turbolinks (5.0.0)
Rails 4.2.2
是否有 DRY 使您的应用中的每个 link_to data: {turbolinks: false}
?或者这是否违背了 Turbolinks 的目的并建议将其删除?
Is there DRY to make every link_to in your app data: {turbolinks: false}
? or does that defeat the purpose of Turbolinks and suggest that it should just be removed?
如果链接被点击,我的大量 jquery 脚本将无法正常工作,除非它包含 data: {turbolinks: false }
,重新加载页面时脚本将正常工作.
A large number of my jquery scripts will not work correctly if a link is clicked unless it contains data: {turbolinks: false }
, the scripts will work correctly when the page is reloaded.
我的 jquery 包含在:$(document).on('turbolinks:load', function () { #something here});
I have my jquery wrapped in: $(document).on('turbolinks:load', function () { #something here});
推荐答案
所以,你问的问题是如何干掉我无尽的链接注释?"我先回答一下...
So, the question you asked was "how to DRY up my endless link annotations?" I'll answer that, first...
是的,如果你 turbolinks: false
一切,那么是的,你应该删除 Turbolinks.不是因为它是 DRY 的,而是因为你在任何地方都禁用了 Turbolinks,不妨将其删除.它不做任何事情但处理链接点击.
Yes, if you turbolinks: false
everything, then yes, you should just remove Turbolinks. Not because it's DRY, but because then you're disabling Turbolinks everywhere and might as well remove it. It doesn't do anything but deal with link-clicking.
不过,如果我能这么大胆,我想你真正的问题是:
If I can be so bold, though, I think your real question is:
我如何让这些很酷的 jQuery 插件工作?我想要它们,我从来没有真正要求过 Turbolinks."
在没有进入特定插件的情况下,它们中的许多都锁定了 jQuery 的 $
函数,该函数附加到 DOMContentLoaded
.Turbolinks 会触发不同的事件(在 Turbolinks-Classic 中是 page:load
事件... 在 Turbolinks 5 中,它是 turbolinks:load
事件,不会发出该事件,也不会重置这些事件处理程序.
Without getting into specific plugins, many of them latch onto jQuery's $
function, which attaches to DOMContentLoaded
. Turbolinks fires a different event instead (in Turbolinks-Classic this was the page:load
event... in Turbolinks 5 it's the turbolinks:load
event, that event isn't emitted and those event handlers don't get reset.
关于如何构建 JavaScript 初始值设定项的一个可能答案是 这里.
One possible answer for how to structure your JavaScript initializers is here.
我个人一直坚持使用 Turbolinks,作为最后一个建议,我将向您推荐 Nate Berkopec 的文章 100 毫秒到带有 Rails 和 Turbolinks 的 Glass.他提出了一个合理的理由来说明为什么 Turbolinks 是一件好事.
I personally have stuck with Turbolinks, and as one last pitch, I'll point you towards Nate Berkopec's article 100ms to Glass with Rails and Turbolinks. He makes a reasonable case for why Turbolinks is a Good Thing.
这篇关于有没有办法绕过写入数据:{turbolinks: false} 无数次?用于轨道的 turbolinks 值得吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!