【问题标题】:Backbone.js and JQuery Mobile RouterBackbone.js 和 JQuery 移动路由器
【发布时间】: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 页面。
这有什么问题?

【问题讨论】:

标签: jquery jquery-mobile routing backbone.js coffeescript


【解决方案1】:

我使用了这里描述的模式: http://coenraets.org/blog/2012/03/using-backbone-js-with-jquery-mobile/.

非常短,非常高效,最重要的是——它有效。

【讨论】:

  • 您应该在链接中发布一些内容。如果链接失败,那么这对其他用户没有帮助。
猜你喜欢
  • 2012-12-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-01
  • 2013-01-25
  • 2013-05-06
  • 2014-09-18
相关资源
最近更新 更多