5

我正在使用jquery mobile 和backbonejs。有点卡在启用了转换属性的骨干路由上。任何建议都会很棒..

      define(['jquery'], function ($) {
      $(document).on("mobileinit", function () {
          $.mobile.ajaxEnabled = false;
          $.mobile.linkBindingEnabled = false;
          $.mobile.hashListeningEnabled = false;
          $.mobile.pushStateEnabled = false;
          $.mobile.defaultPageTransition = "slide";
     });
});

但幻灯片过渡不起作用。


路由器的代码如下

define([
'jquery',
'underscore',
'backbone',
'backbone.subroute'], function($, _, Backbone) {
var AppRouter = Backbone.Router.extend({
    routes: {
        // general routes 
        '': 'defaultAction',
        'login':'login',
        'message':'message',
        'menu': 'mainMenu',
     
        // Default
        '*actions': 'defaultAction'
    }
});

var initialize = function() {

        $('.back').live('click', function(event) {
            event.preventDefault();
            window.history.back();
            return false;
        });

    var app_router = new AppRouter;
    app_router.on('route:defaultAction', function(actions) {
        require(['views/home/register'], function(RegisterView) {
            // We have no matching route, lets display the home page 
            console.log('At defaultAction');
        var registerView = new RegisterView();
        registerView.render();
           /// this.changePage(loginView, 'slide');
        });
    });
  
     app_router.on('route:login', function(actions) {
        require(['views/home/login'], function(LoginView) {
            // We have no matching route, lets display the home page 
            console.log('At defaultAction');
        var loginView = new LoginView();
        loginView.render();
           /// this.changePage(loginView, 'slide');
        });
    });
    app_router.on('route:mainMenu', function(actions) {
        require(['views/home/menu'], function(MainMenuView) {
            console.log('At mainMenu::router');
        var mainMenuView = new MainMenuView();
        mainMenuView.render();
          //  this.changePage(mainMenuView, 'slide');
});
    });

我们可以在这里使用 cal changePage 进行转换吗?

4

1 回答 1

1

这可以在 init.js 文件中。

(函数($){

    var appRouter = Backbone.Router.extend({ 
            routes: {   "": "showActivitiesPage"
            },

            showActivitiesPage: function() {                
                $.mobile.changePage("#activities", { reverse: false, changeHash: false });                          
            }           
    }); 

}(jQuery));

您可以使用更改页面,即使哈希侦听设置为 false JQM/backbone 也不会阻止我们使用更改页面和哈希路由。

查看此链接,它在所有一个字段中都有一个示例,但您可以将其分解为控制器、模型和视图

http://blog.chariotsolutions.com/2011/12/introduction-to-backbonejs-with-jquery.html

在上述示例的上下文中:

控制器:

(function($){
$('#activities').live('pageinit', function(event){
    var activitiesListContainer = $('#activities').find(":jqmData(role='content')"),
        activitiesListView;
    exercise.initData();
    activitiesListView = new exercise.ActivityListView({collection: exercise.activities, viewContainer: activitiesListContainer});
    activitiesListView.render();
});

}(jQuery));

模型:

(函数($){

exercise.Activity = Backbone.Model.extend({
});

exercise.Activities = Backbone.Collection.extend({
    model: exercise.Activity,
    url: "exercise.json"
});

}(jQuery));

看法:

(function($){
exercise.ActivityListView = Backbone.View.extend({
        tagName: 'ul',
        id: 'activities-list',
        attributes: {"data-role": 'listview'},

        initialize: function() {
            this.template = _.template($('#activity-list-item-template').html());
        },

        render: function() {
            var container = this.options.viewContainer,
                activities = this.collection,
                template = this.template,
                listView = $(this.el);

            $(this.el).empty();
            activities.each(function(activity){
                listView.append(template(activity.toJSON()));
            });
            container.html($(this.el));
            container.trigger('create');
            return this;
        }
    });
}(jQuery));

运动可以是全局变量。

于 2013-07-15T08:31:38.820 回答