2012-12-12 42 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 : { 
... 
相关问题