如何在一個應用程序中一起使用jQuery Mobile和Backbone JS?

[英]How to use jQuery Mobile and Backbone JS together in one app?


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.

我一直很喜歡使用Backbone JS進行iPad HTML5項目...但我很快就遇到了需要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 View。基本上完全取消了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如何無縫地協同工作?我該怎么做,向前邁進?

4 个解决方案

#1


8  

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

布拉德

#2


4  

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

進一步的證據是刪除autoInitialize選項,因為它們從alpha 3變為alpha 4: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。

#3


1  

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

我更喜歡更集成的w / jquery移動設備,所以我通常用這個替換主干路由器:github.com/azicchetti/jquerymobile-router。很好地工作

#4


0  

Found this and it worked perfectly for me: Redirect from mobile site (jQuery mobile) to main site styles linger

發現這一點,它對我來說非常有效:從移動站點(jQuery mobile)重定向到主站點樣式

I was redirecting to the main site and it kept throwing "Backbone history started" errors

我正在重定向到主站點,它不斷拋出“Backbone history started”錯誤


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2011/04/04/72f0c2de9cd70f59fd70e616f04bc05a.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com