2012-12-12 122 views
0

我使用需要在我的應用程序,並在某些Android設備,並時不時在網上我得到這樣的jQuery的錯誤沒有被定義或沒有定義骨幹網]上(在爲了防止錯誤加載)需要依賴

我的索引頁是簡單和有一個鏈接到我需要

<script data-main="js/main" src="js/vendor/require/require.js"></script> 

內這裏我設置的所有路徑和呼叫路由器,以及關掉路由的JQM

require.config({ 

paths: { 
    jquery:  'vendor/jqm/jquery_1.7_min', 
    jqm:  'vendor/jqm/jquery.mobile-1.1.0', 
    underscore: 'vendor/underscore/underscore_amd', 
    backbone: 'vendor/backbone/backbone_amd', 
    text:  'vendor/require/text', 
    templates: '../templates', 
    views: '../views', 
    models:  '../models' 
} 

}); 

define(['router','jqm-config'], function(app) { 
}); 

然後我的路由器頁面上,我定義什麼是需要有..

define(['jquery', 'underscore', 'backbone','views/home/home', 
     'models/products/productCollection', 
     'views/products/productTypes', 
     'jqm'], 
function($, _, Backbone,HomeView,ProductsType,ProductListView) { 

     var AppRouter = Backbone.Router.extend({ 
     //code here 
     }); 

$(document).ready(function() { 
    console.log('App Loaded'); 
    app = new AppRouter(); 
    Backbone.history.start(); 
    }); 

    return AppRouter; 
}); 

如何停止這些錯誤出現?

回答

1

在你require.config您可以添加一個墊片部分來定義這些依賴:

require.config({ 
    // The shim config allows us to configure dependencies for 
    // scripts that do not call define() to register a module 
    shim : { 
    'underscore' : { 
     exports : '_' 
    }, 
    'backbone' : { 
     deps : [ 'underscore', 'jquery' ], 
     exports : 'Backbone' 
    }, 
    'dataTables' : { 
     deps : [ 'jquery' ], 
     exports : 'dataTables' 
    } 
    }, 
    paths : { 
...