2014-01-06 64 views
-3

我的RequireJS有一個很大的proglem。該配置隨機工作。我不知道爲什麼,一旦它的工作原理,一旦它並不:Backbone + JQuery Mobile + RequireJS

requirejs.config({ 
    baseUrl: 'js', 
    urlArgs: "bust=" + (new Date()).getTime(), 
    paths: { 
    jquery: 'libs/jquery/jquery-1.10.2.min', 
    underscore: 'libs/underscore/underscore-min', 
    backbone: 'libs/backbone/backbone-min', 
    marionette: 'libs/marionette/backbone.marionette', 
    cordova: 'libs/cordova/cordova-1.9.0', 
    jquerym: 'libs/jquery-mobile/jquery.mobile-1.4.0' 
    }, 

    shim: { 
    'jquery': { 
     deps: [] 
    }, 
    'jquerym': { 
     deps: ['jquery'], 
     exports: 'jquery' 
    }, 
    'underscore': { 
     deps: [], 
     exports: "_" 
    }, 
    'backbone': { 
     deps: ['jquery', 'underscore'], 
     exports: 'Backbone' 
    }, 
    'marionette': { 
     deps: ['jquery', 'underscore', 'backbone'] 
    } 
    }, 
    priority: ['jquery', 'jquerym'] 
}); 


require(['app', 'jquery', 'jquerym'], function (App) { 
    $(document).bind("mobileinit", function() { 
    $.mobile.ajaxEnabled = false; 
    $.mobile.linkBindingEnabled = false; 
    $.mobile.hashListeningEnabled = false; 
    $.mobile.pushStateEnabled = false; 
    // Remove page from DOM when it's being replaced 
    $('div[data-role="page"]').live('pagehide', function (event, ui) { 
     $(event.currentTarget).remove(); 
    }); 
    }); 

    console.log('jQuery version ' + $().jquery + ' installed'); 
    App.initialize(); 
}); 
+2

究竟是什麼失敗了?你會收到錯誤消息嗎?你想達到什麼目的。請更新您的問題以使其更清楚。另外,請縮進您的代碼。 – rednaw

+0

Thermost沒有消息在控制檯日誌中的每一件事情都很好,但有些時候jquery mobile不加載。很奇怪。 – reizals

+0

我發現類似的東西發生在require.js和jquerymobile上,但到目前爲止,它只在Android瀏覽器上打破 - 我沒有目睹它在FF或Chrome上破解。我已經使用jquery和jquerymobile從require.js中取出 - 這是一個可以殺死它的urlArgs。 –

回答

3

的移動-INIT-事件面前jQuery Mobile的加載它被正確觸發的約束。 嘗試使用類似這樣的東西:

require(["jquery"], function($){ 
    $(document).one("mobileinit", function() { 
     //Set your configuration and event binding 
     $.mobile.ajaxEnabled = false; 
     $.mobile.linkBindingEnabled = false; 
     $.mobile.hashListeningEnabled = false; 
     $.mobile.pushStateEnabled = false; 
     // Remove page from DOM when it's being replaced 
     $('div[data-role="page"]').live('pagehide', function (event, ui) { 
      $(event.currentTarget).remove(); 
     }); 
    }); 

    require([ "App", "jquerym" ], function(App, jqm) { 
     /* Do Stuff with jqm here if you want like jqm.initializePage() if turned off */ 
     App.initialize(); 
    }); 
}); 
+0

我試過,但問題仍然存在... –

相關問題