相关疑难解决方法(0)

使用RequireJS加载Backbone和Underscore

我正在尝试使用RequireJS加载Backbone和Underscore(以及jQuery).使用最新版本的Backbone和Underscore,看起来有点棘手.例如,Underscore自动将自己注册为模块,但Backbone假设Underscore在全球范围内可用.我还应该注意,Backbone似乎没有将自己注册为一个模块,这使得它与其他库不一致.这是我能想到的最好的main.js:

require(
{
    paths: {
        'backbone': 'libs/backbone/backbone-require',
        'templates': '../templates'
    }
},
[
    // jQuery registers itself as a module.
    'http://cdnjs.cloudflare.com/ajax/libs/jquery/1.7/jquery.min.js',

    // Underscore registers itself as a module.
    'http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.2.1/underscore-min.js'
], function() {

    // These nested require() calls are just due to how Backbone is built.  Underscore basically says if require()
    // is available then it will automatically register an "underscore" module, but it won't register underscore
    // as a global "_".  However, Backbone expects Underscore to be a global variable.  To …
Run Code Online (Sandbox Code Playgroud)

javascript requirejs backbone.js underscore.js

172
推荐指数
3
解决办法
7万
查看次数

Bootstrap - 未捕获的TypeError:无法读取未定义的属性"fn"

我正在为我的公司项目使用jquery,backbonejs,underscorejs和bootstrap.有时我在chrome中遇到这个错误.

未捕获的TypeError:无法读取未定义的属性"fn"

在我的main.js中,我的垫片是这样的

require.config({
paths: {
    jquery: 'libs/jquery/jquery',
    underscore: 'libs/underscore/underscore',
    backbone: 'libs/backbone/backbone',
    backboneeventbinder: 'libs/backbone.eventbinder.min',
    bootstrap: 'libs/bootstrap',
    jquerytablesorter: 'libs/tablesorter/jquery.tablesorter',
    tablesorter: 'libs/tablesorter/tables',
    ajaxupload: 'libs/ajax-upload',
    templates: '../templates'
},
shim: {
    'backbone': {
        deps: ['underscore', 'jquery'],
        exports: 'Backbone'
    },
    'underscore': {
        exports: '_'
    },
}
});
 require(['app', ], function(App) {
  App.initialize();
});
Run Code Online (Sandbox Code Playgroud)

我已经为jquery,underscorejs和backbonejs插入了.noConflict().

我的app.js.

// Filename: app.js
define(['jquery', 'underscore', 'backbone', 'backboneeventbinder', 'bootstrap', 'ajaxupload', 'router', // Request router.js
], function($, _, Backbone, Bootstrap, Backboneeventbinder, Ajaxupload, Router) {
    $.noConflict();
    _.noConflict();
    Backbone.noConflict();
    var initialize = function() { …
Run Code Online (Sandbox Code Playgroud)

jquery shim backbone.js underscore.js twitter-bootstrap-3

29
推荐指数
4
解决办法
10万
查看次数