Backbone.js 和 JQuery 移动路由器
我正在使用 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 页面未找到。
这有什么问题吗?
I'm developing an application with Backbone.js and JQM, but I have problems with methods not being fired.
This is my code:
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) }
Setting the route to #home, it is not get called.
However if I set it to just home, and disable both ajax and hashListening like this
$.mobile.ajaxEnabled = false;
$.mobile.hashListeningEnabled = false;
Brings me to a 404 page not found.
What's the problem with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用了这里描述的模式:
http://coenraets.org/blog/2012/ 03/using-backbone-js-with-jquery-mobile/。
非常短,非常高效,最重要的是——它有效。
I have used the pattern described here:
http://coenraets.org/blog/2012/03/using-backbone-js-with-jquery-mobile/.
Very short, very efficient, and most important - it works.