如何在我的Emberjs Rails应用程序中包含jQuery Mobile

时间:2021-01-15 22:45:59

Today I encounter a puzzling issue and after several hours of searching I am not able to find what is the problem. I am trying to include jquery mobile into my rails application. I have tried both manually referencing the library files and also using jquery_mobile_rails gem. Both method works as far as inserting the library into my application, however as soon as I add jquery mobile, my app no longer loads. When refreshing the page, it will not load. There are three errors in console:

今天我遇到了一个令人费解的问题,经过几个小时的搜索,我无法找到问题所在。我试图将jquery mobile包含到我的rails应用程序中。我既尝试手动引用库文件又尝试使用jquery_mobile_rails gem。两种方法都可以将库插入我的应用程序,但是只要我添加jquery mobile,我的应用程序就不再加载了。刷新页面时,不会加载。控制台中有三个错误:

1st:

Uncaught TypeError: Object <Ember.ArrayResourceController:ember141> has no method '_resourceRequest'
Jimux.appsMetaController.Em.ArrayResourceController.create.findAll
newFunc
(anonymous function)
(anonymous function)
(anonymous function) jquery.js:566
jQuery.extend.globalEval jquery.js:567
jQuery.ajaxSetup.converters.text script jquery.js:8107
ajaxConvert jquery.js:7992
done jquery.js:7628
callback jquery.js:8367
send jquery.js:8373
jQuery.extend.ajax jquery.js:7835
(anonymous function) jquery.js:5858
jQuery.extend.each jquery.js:613
jQuery.fn.extend.domManip jquery.js:5855
jQuery.fn.extend.append jquery.js:5628
jQuery.fn.extend.wrapAll jquery.js:5585
(anonymous function) jquery.js:5603
jQuery.extend.each jquery.js:613
jQuery.fn.jQuery.each jquery.js:243
jQuery.fn.extend.wrapInner jquery.js:5598
$.extend.initializePage jquery.mobile-1.2.0.js:9063
(anonymous function) jquery.mobile-1.2.0.js:9142
fire jquery.js:976
self.fireWith jquery.js:1084
jQuery.extend.ready jquery.js:408
DOMContentLoaded

2nd:

Uncaught TypeError: Cannot call method 'set' of undefined
Ember.Application.registerInjection.injection
(anonymous function)
(anonymous function)
visit
DAG.topsort
Ember.Application.Ember.Namespace.extend.runInjections
Ember.Application.Ember.Namespace.extend.initialize
(anonymous function)
fire
self.fireWith
jQuery.extend.ready

3rd:

GET http://localhost:3000/assets/images/ajax-loader.gif 404 (Not Found)

As soon as I remove //= require jquery.mobile-1.2.0 from application.js, my app works as expected again -- without any of the above errors. I am just wondering what could be happening here. I guess there may be some namespace collision, but I am not sure if this is the case and how to identify and fix it.

一旦我从application.js中删除// = require jquery.mobile-1.2.0,我的应用程序就会再次按预期工作 - 没有任何上述错误。我只是想知道这里会发生什么。我想可能存在一些命名空间冲突,但我不确定是否是这种情况以及如何识别和修复它。

Any help with debugging this issue will be appreciated. If you are using Embeejs+jQueryMobile in a rails project, I would love to know how you are including the two libraries into your rails application, and if/how you are dealing with any conflict.

任何有关调试此问题的帮助将不胜感激。如果您在rails项目中使用Embeejs + jQueryMobile,我很想知道您如何将两个库包含到rails应用程序中,以及是否/如何处理任何冲突。

I am using Ember 1.0pre1, and a slightly modified version of ember-rest.

我正在使用Ember 1.0pre1,以及稍微修改过的ember-rest版本。

1 个解决方案

#1


3  

If I recall correctly, jQuery Mobile manipulates the DOM a fair bit. That would likely be problematic with Ember, as Ember expects to not have other libraries manipulating DOM elements that it is tracking views or bindings for.

如果我没记错的话,jQuery Mobile会对DOM进行一些操作。这可能是Ember的问题,因为Ember希望没有其他库操纵DOM元素,它正在跟踪视图或绑定。

#1


3  

If I recall correctly, jQuery Mobile manipulates the DOM a fair bit. That would likely be problematic with Ember, as Ember expects to not have other libraries manipulating DOM elements that it is tracking views or bindings for.

如果我没记错的话,jQuery Mobile会对DOM进行一些操作。这可能是Ember的问题,因为Ember希望没有其他库操纵DOM元素,它正在跟踪视图或绑定。