Backbone.js and jQueryMobile routing without hack or other router

后端 未结 3 1004
独厮守ぢ
独厮守ぢ 2020-12-15 14:05

I am using backbone.js (0.5.3) with JQueryMobile (1.0 beta 2). I know there are routing conflicts when using those libraries together, and I would like to know if there is a

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-15 14:29

    This may be a bit of a longshot as I have no way to test it, but try extending Backbone's history, and have it listen for a creation event before actually firing off the code. So..

    MyHistory = Backbone.History.extend({
        loadUrl : function(fragmentOverride) {
          var fragment = this.fragment = this.getFragment(fragmentOverride);
          var matched = _.any(this.handlers, function(handler) {
            if (handler.route.test(fragment)) {
              //This is the only change from core code.. 
              //We're just wrapping it into a callback.
              $('.ui-page-active').one('pagecreate', function () {
                  handler.callback(fragment);
              });
              return true;
            }
          });
          return matched;
        }
    });
    MyHistory.start();
    

    That might do it, or at least get you on the right path I hope.

提交回复
热议问题