[英]How to use jquery in non-react javascript on rails?
I've recently incorporated The react_on_rails (NOT react-rails
) Gem into my rails 4.2 code base. 我最近将react_on_rails (NOT
react-rails
)Gem合并到我的rails 4.2代码库中。
I want to introduce new react components into an app that already has a fair amount of javascript code. 我想在已经拥有相当数量的javascript代码的应用程序中引入新的反应组件。
I ran the "hello world" generator for react on rails which, among other things, commented out the //= require jquery
line from my application.js
-- as a result of this my pre-existing coffeescript (which depended on jquery
being present) no longer works. 我运行了“hello world”生成器,用于对rails进行响应,其中包括从我的
application.js
注释掉//= require jquery
行 - 这是我之前存在的coffeescript(依赖于jquery
的结果)现在)不再有效。 But the new generated demo hello world
react components do work. 但新生成的演示
hello world
react组件确实有效。
When i comment out the added //= require vendor-bundle
and //= require app-bundle
lines from my application.js
and add back in the //= require jquery
lines -- the opposite happens, the react components stop working but the pre-existing coffeescript works again. 当我从我的
application.js
注释掉添加的//= require vendor-bundle
和//= require app-bundle
行并添加回//= require jquery
- 相反的情况发生,反应组件停止工作但是预先存在的coffeescript再次起作用。
My question is -- how do i set things up so that BOTH work? 我的问题是 - 我如何设置,以便两个工作? That is, that the new react components work, AND the pre-existing coffeescript (that relies on jquery) works as well.
也就是说,新的反应组件工作,并且预先存在的coffeescript(依赖于jquery)也可以工作。
Thanks in advance! 提前致谢!
I haven't used the generator, so I'm not sure what all it contains. 我没有使用过发生器,所以我不确定它包含的是什么。 But I do have the react-rails gem and jquery working in a bunch of my apps, so here's what my imports look like;
但是我确实让react-rails gem和jquery在我的应用程序中运行,所以这就是我的导入的样子;
application.js 的application.js
//= require jquery
//= require react
//= require jquery_ujs
//= require react_ujs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.