2013-12-16 46 views
6

我正在为我的公司项目使用jquery,backbonejs,underscorejs和bootstrap。有时我在Chrome中遇到了这个错误。Bootstrap - 未捕获TypeError:无法读取undefined属性'fn'

Uncaught TypeError: Cannot read property 'fn' of undefined

我垫片是这样的,我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(); 
}); 

我已经插入.noConflict()的jQuery,underscorejs和backbonejs。

我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() { 
      Router.initialize(); 
     }; 
    return { 
     initialize: initialize 
    }; 
}); 

这是截图从Chrome enter image description here

它有点像来引导有关。

非常感谢。

+0

如何使用'noConflict'? –

+0

This [answer](http://stackoverflow.com/a/11184070/122005)也许是有用的 – chridam

回答

19

我需要在引导之前首先加载jquery。

require.config({ 
    paths: { 
     jquery: 'libs/jquery/jquery', 
     underscore: 'libs/underscore/underscore', 
     backbone: 'libs/backbone/backbone', 
     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' 
     }, 
     'jquery': { 
      exports: '$' 
     }, 
     'bootstrap': { 
      deps: ['jquery'], 
      exports: '$' 
     }, 
     'jquerytablesorter': { 
      deps: ['jquery'], 
      exports: '$' 
     }, 
     'tablesorter': { 
      deps: ['jquery'], 
      exports: '$' 
     }, 
     'ajaxupload': { 
      deps: ['jquery'], 
      exports: '$' 
     }, 
     'underscore': { 
      exports: '_' 
     }, 
    } 
}); 
require(['app', ], function(App) { 
    App.initialize(); 
}); 

固定与魅力!

+0

真的,你需要先加载jquery:D – Fiido93

0
//Call .noConflict() to restore JQuery reference. 

jQuery.noConflict(); OR $.noConflict(); 

//Do something with jQuery. 

jQuery("div.class").hide(); OR $("div.class").show(); 
+0

你应该指定何时调用'noConflict()':在包含jQuery之后。 http://api.jquery.com/jQuery.noConflict/ – TheBronx

+0

它不起作用 –

相关问题