好的解決方案是禁用jQuery Mobile ajax加載功能並手動調用$.mobile.changePage
方法。
HTML頁面:
<script type="text/javascript" charset="utf-8" src="js/mobile/jquery.js"></script>
<script type="text/javascript">
$(document).bind("mobileinit", function(){
$.mobile.ajaxEnabled = false;
$.mobile.hashListeningEnabled = false;
});
</script>
<script type="text/javascript" charset="utf-8" src="js/mobile/jquery-mobile.js"></script>
然後,每當一個新的路線被觸發時,我首先建立在骨幹查看構造我的新的「jQuery的頁面畫布」,其追加到HTML文檔body
並設置我的el
查看元素到這個新的div
:
骨幹。查看
$("body").prepend("""
<div id="my-id" data-role="page" class="cloudy-background-mobile">
<div class="cloudy-header" data-role="header" data-position="fixed"></div>
<div class="cloudy-content" data-role="content"></div>
</div>
""")
this.el = $("#logs-view")
而在render
方法:
// Build the content using undescore.js templating system
this.el.find('.cloudy-content').html(this.template({logs : this.collection}));
this.find('.cloudy-header').html(this.template_header({logbook: this.logbook}));
// Change the page using jquery mobile and reapply jquery styles
$.mobile.changePage(this.el, "slide", false, false);
this.trigger("pagecreate");
就像一個魅力,沒有任何不必要的黑客:)
這裏是我的全部骨幹查看它是否能夠幫助任何人:
class LogsView extends Backbone.View
constructor: (options) ->
super
$("body").prepend("""
<div id="logs-view" data-role="page" class="cloudy-background-mobile">
<div class="cloudy-header" data-role="header" data-position="fixed"></div>
<div class="cloudy-content" data-role="content"></div>
</div>
""")
@el = $("#logs-view")
@logbook = options.logbook
@collection.bind 'reset', @render
@template = _.template('''
<ul data-role="listview" data-theme="c" data-inset="true">
<% logs.each(function(log){ %>
<li>
<a href="#logs-<%= log.cid %>"><%= log.getLabel() %></a>
</li>
<% }); %>
</ul>
''')
@template_header = _.template('''
<h1>Carnets <%= logbook.get('name') %></h1>
<a href="#logbook-<%= logbook.cid %>-logs-new" data-icon="plus" class="ui-btn-right"> </a>
''')
render: =>
# Build the content using undescore.js templating system
@el.find('.cloudy-content').html(@template({logs : @collection}))
@el.find('.cloudy-header').html(@template_header({logbook: @logbook}))
# Change the page using jquery mobile and reapply jquery styles
$.mobile.changePage(@el, "slide", false, false)
@el.trigger("pagecreate")
你在哪個事件中啓動了你的應用程序? $('document')。ready()或$(document).bind('pageinit')?我試圖按照你的建議,但遇到骨幹路由器錯誤。 – fbuchinger
注意:$(document).bind(「mobileinit」...調用必須在加載jquery之前和加載jquery mobile之前進行 – pws5068