我正在尝试禁用jquerymobile的漫游功能,但会出现错误加载页面,并且url未被主干捕获。我已禁用jqeurymobile的所有参数,如在一些教程中所述。

在这里禁用jquerymobile:

       require.config({
     paths: {
    jQuery: '../libs/jquery/jquery-loader',
    jQueryMobile: '../libs/jquery.mobile/jquery.mobile-loader',
    underscore: '../libs/underscore/underscore-loader',
    Backbone: '../libs/backbone/backbone-loader',
    order: '../libs/require/order-1.0.5',
    text: '../libs/require/text-1.0.6',
    async: '../libs/require/async',
    //PhoneGap: '../libs/phonegap/phonegap-loader',
    Handlebars: '../libs/handlebars/Handlebars',
    templates: '../templates'
        }
        });

         require(['order!jQuery'], function($) {

      // jQueryMobile configuration
       $(document).bind("mobileinit", function() {
    $.mobile.ajaxEnabled = false;
    $.mobile.autoInitializePage = false;
    $.mobile.linkBindingEnabled = false;
    $.mobile.hashListeningEnabled = false;
    $.mobile.pushStateEnabled = false;
    $.mobile.changePage.defaults.changeHash = false;
    $.mobile.pageContainer = $("body");

    // Remove page from DOM when it's being replaced, otherwise the DOM will contain
    all of them
    $('div[data-role="page"]').on('pagehide', function(event, ui) {
        $(event.currentTarget).remove();
    });
     });

     // We launch the App
       // jQueryMobile is referenced in order to start its initialization
      require(['underscore', 'Backbone', 'router', 'jQueryMobile'], function(_,
       Backbone, AppRouter, jQueryMobile) {



    document.addEventListener("deviceready", run, false);
     run();

    function run() {

        var sync = Backbone.sync;
      Backbone.sync = function(method, model, options) {
      options.beforeSend = function (xhr) {
      xhr.setRequestHeader('X-Parse-Application-Id', 'niI
      BCf78Rfe1wu**yQWUrr6A3yyhex3M');
      xhr.setRequestHeader('X-Parse-REST-API-Key', 'l4CgjESBwPYA**3Pq1V1LKHTvuhQj');
          };



        sync(method, model, options);

      },

        app = new AppRouter();
        Backbone.history.start();

        Parse.$ = jQuery;


       Parse.initialize("niIBCf***7tbnyQWUrr6A3yyhex3M",
               "HD4bsMvPh3T*YvT1MIdOh2GR");

          }
        })
         });


在这里声明url的地方:

         <div data-role="navbar" data-theme="d" data-position="fixed">
                    <ul>
                        <li><a href="#" data-icon="grid"></a></li>
                        <li><a href="#/insert" data-icon="home"></a></li>
                        <li><a href="#" data-icon="search"></a></li>
                    </ul>
                </div><!-- /navbar -->

最佳答案

我一直遇到同样的问题!起初,我认为这可能是因为我所看到的所有示例(jquerymobile网站和addy osmain的网站)都使用了旧版本的jqm,并且我认为新版本可能有问题。

但是回头看一下代码,我看到了我的问题所在:在需要jquerymobile之前,请务必使您的“ mobile init”绑定。

在jqm文档中,您可以看到基本原理:

http://api.jquerymobile.com/global-config/

这是我的工作代码(位于我的requireJS引导程序app.js中):

// Includes File Dependencies
require(
    ['require', 'backbone', 'jquery', 'underscore' ],
    function( require, Backbone, $, _ ) {
        // framework loaded
        console.log('framework libraries loaded');

        $( document ).on( "mobileinit",
            // Set up the "mobileinit" handler before requiring jQuery Mobile's module
            function() {

                //apply jquery mobile overrides here

                // Disabling this will prevent jQuery Mobile from handling hash changes
                $.mobile.hashListeningEnabled = false;

                // Prevents all anchor click handling including the addition of active button state and alternate link bluring.
                $.mobile.linkBindingEnabled = false;

            }
        );

        require(
                ['require', 'jquerymobile', 'app'],
                function( require,  Mobile ) {

                    console.log('jq mobile has been loaded...');

                    // when jquery mobile is first ready to go, remove hidden on main container div
                    // if this isn't done, we'll see a flash of unenhanced DOM before jqm can get to it
                    $('#body-container').removeClass('hidden');

                }
        );
    }
);

关于javascript - Backbone 和jquerymobile:无法禁用路由,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16877144/

10-11 17:12