javascript 如何在一个应用程序中同时使用 jQuery Mobile 和 Backbone JS?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5537993/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use jQuery Mobile and Backbone JS together in one app?
提问by littlejim84
I've been enjoying using Backbone JS for a iPad HTML5 project... But I'm quickly running into a issue of needing iPad-ish transitions, form elements etc. After looking around, it seems jQuery Mobile is the most established. We use jQuery anyhow.
我一直很喜欢在 iPad HTML5 项目中使用 Backbone JS...但我很快就遇到了需要 iPad-ish 过渡、表单元素等的问题。环顾四周后,似乎 jQuery Mobile 是最成熟的。无论如何我们都使用jQuery。
But one thing I quickly ran into was the hash events/ajax stuff of the two libraries quickly didn't work. Because jQuery Mobile takes care of loading in pages, and doing the transitions etc, it was not letting my Backbone Controller routes work as they did before. It seemed that the two aren't actually that compatible?
但是我很快遇到的一件事是两个库的哈希事件/ajax 内容很快就不起作用了。因为 jQuery Mobile 负责加载页面和执行转换等,所以它不会让我的 Backbone Controller 路由像以前那样工作。两个人好像真的不太搭?
After some work though, I have a basic workaround... Using the page loading events stuff in jQuery Mobile to see the active page it's on and then fire the correct Backbone View that goes with that page. Basically doing away completely with Backbone's hash listening/routes/controller.
经过一些工作,我有了一个基本的解决方法......使用 jQuery Mobile 中的页面加载事件来查看它所在的活动页面,然后触发与该页面一起使用的正确 Backbone 视图。基本上完全取消了 Backbone 的哈希监听/路由/控制器。
But this still doesn't seem right? How can Backbone JS and jQuery Mobile work seamlessly together? How do I do this right, moving forward?
但这似乎仍然不对?Backbone JS 和 jQuery Mobile 如何无缝协同工作?我如何正确地做到这一点,继续前进?
采纳答案by bradgonesurfing
I think I found a solution when I asked the same question.
当我问同样的问题时,我想我找到了解决方案。
Disable the hash change controller in JQuery mobile UI and replace with backbone.js
禁用 JQuery 移动 UI 中的哈希更改控制器并替换为backbone.js
There looks to be an option to disable JQuery hash change listening on a recent checking.
似乎有一个选项可以禁用 JQuery 哈希更改侦听最近的检查。
https://github.com/jquery/jquery-mobile/commit/3162428558efd9960739ef8f00a7ead0dbf6d3ec
https://github.com/jquery/jquery-mobile/commit/3162428558efd9960739ef8f00a7ead0dbf6d3ec
I have not tried it yet though. If it works please let us know.
我还没有尝试过。如果有效,请告诉我们。
Brad
布拉德
回答by Mike McKay
It seems that the JQuery Mobile team has made a conscious decision to not support the sort of dynamic applications the Backbone.js targets. From the alpha 4 release notes:
似乎 JQuery Mobile 团队做出了一个有意识的决定,不支持 Backbone.js 所针对的那种动态应用程序。来自alpha 4 发行说明:
After 1.0 is out, the project be focusing on ... dynamic applications, expanded widget set, and ... A more detailed roadmap is underway and we'll share it as we get closer to our 1.0 release.
1.0 发布后,该项目将专注于...动态应用程序、扩展的小部件集,以及...更详细的路线图正在进行中,我们将在接近 1.0 版本时分享它。
Further evidence for this is the removal of the autoInitialize option as they went from alpha 3 to alpha 4: issue 1391
进一步的证据是在从 alpha 3 到 alpha 4 时删除了 autoInitialize 选项:issue 1391
So for now, we need workarounds. An alternative answer is to help fix outstanding JQM bugs and push it closer to 1.0, so we can get dynamic application features into JQM ASAP.
所以现在,我们需要解决方法。另一个答案是帮助修复突出的 JQM 错误并将其推向 1.0,以便我们可以尽快将动态应用程序功能引入 JQM。
回答by petermaury
i prefer something more integrated w/ jquery mobile, so i usually replace backbone's router with this one: github.com/azicchetti/jquerymobile-router . works nicely
我更喜欢与 jquery mobile 更集成的东西,所以我通常用这个替换主干的路由器:github.com/azicchetti/jquerymobile-router。效果很好
回答by Brandon
Found this and it worked perfectly for me: Redirect from mobile site (jQuery mobile) to main site styles linger
找到了这个,它对我来说非常有效: 从移动站点(jQuery 移动)重定向到主站点样式仍然存在
I was redirecting to the main site and it kept throwing "Backbone history started" errors
我正在重定向到主站点,它不断抛出“Backbone history started”错误