javascript - RequireJs 没有正确加载依赖项

标签 javascript twitter-bootstrap require

在我基于 Web 的应用程序中,我使用 RequireJs 来异步加载脚本,但有时(并非总是)我会收到错误,因为 RequireJs 似乎没有正确加载依赖项。

示例:

require(['jquery-1.7.2.min', 'bootstrap/js/bootstrap.min'], function (){
    //Used for initialize bootstrap tooltip
    $('a[rel]').tooltip();  
});

然后我得到:

Uncaught TypeError: Object [object Object] has no method 'tooltip'

有什么问题?

最佳答案

在创建 AMD 模块时,您应该接受模块输出(即 $ 用于 jQuery)作为自定义模块定义中的参数:

require(['jquery-1.7.2.min', 'bootstrap/js/bootstrap.min'], function ($) {
    //Used for initialize bootstrap tooltip
    $('a[rel]').tooltip();  
});

注意添加 $ 作为函数参数

此外,如果您所在的页面正在加载多个版本或副本的 jQuery(并且未标记为 noconflict,您也可能会遇到问题。

关于javascript - RequireJs 没有正确加载依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14557461/

相关文章:

Ruby:如果更改了文件,则再次需要一个文件

javascript - Elastic Beanstalk 和 ES6

javascript - 具有异步初始化的单例

javascript - 为什么我的appendChild 不起作用?

css - 如何让这个 Bootstrap 导航栏在移动设备上看起来整洁?

javascript - Nodejs延迟返回 "require"

javascript - 计算近似值SVG 椭圆长度? (用Javascript计算近似椭圆周长)

javascript - 使用 DataTable 插件获取具有特定类的表的所有 td 值

css - Bootstrap框架中如何让select元素的值居中位置

ruby gem 需要问题