【发布时间】:2011-12-20 09:56:26
【问题描述】:
我正在使用 Backbone.js 和 JQM 开发一个应用程序,但是我遇到了方法没有被触发的问题。
这是我的代码:
class HomeView extends Backbone.View
constructor: ->
super
@el = app.activePage()
console.log(@el)
@template = _.template('''
<div>
<ul data-role="listview" data-theme="c" data-filter="true">
<% venues.each(function(venue){ %>
<li><a href="#home"><%= venue.getAbstract() %></a></li>
<% }); %>
</ul>
</div>
''')
@render()
render: =>
@el.find('.ui-content').html(@template({venues : Venues}))
app.reapplyStyles(@el)
class HomeController extends Backbone.Controller
routes :
"#venues-:cid" : "show"
"#home" : "home"
constructor: ->
super
@_views = {}
home : ->
console.log("home")
@_views['home'] ||= new HomeView
show: (cid) ->
console.log("show")
@_views["venues-#{cid}"] ||= new ShowVenueView { model : Venues.getByCid(cid) }
将路由设置为#home,它不会被调用。
但是,如果我将其设置为 home,并像这样禁用 ajax 和 hashListening
$.mobile.ajaxEnabled = false;
$.mobile.hashListeningEnabled = false;
将我带到未找到的 404 页面。
这有什么问题?
【问题讨论】:
-
根据我的阅读,JQM 和 Backbone 使用哈希标签的方式存在一些差异。你试过这个:github.com/azicchetti/jquerymobile-router
-
在意识到 jQuery mobile 用于开发针对移动设备优化的 Web 应用程序是多么可怕的选择之前,我遭受了很多痛苦。 BackboneJS 可以处理 jQuery mobile 可以处理的所有事情,它具有更轻的框架和更少突兀的代码。这是一个很好的起点:trigger.io/cross-platform-application-development-blog/2012/03/…
标签: jquery jquery-mobile routing backbone.js coffeescript