2

我正在尝试禁用 jquerymobile 的 rounting,但出现错误加载页面,并且 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 -->   
4

1 回答 1

2

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

但是回顾一下代码,我发现我的问题出在哪里:在需要 jquerymobile 之前,您必须小心地绑定“mobile init”。

在jqm docs中,可以看到基本原理:

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

这是我的工作代码(位于我的 requireJS bootstrap 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');

                }
        );
    } 
);
于 2013-07-04T23:28:55.283 回答