2014-01-25 54 views
2

我在加载jquery-menu-aimbootstrap骨干项目中的Require.js时出错。Require.js中没有定义调用函数

下面是我在main.js已经定义:

requirejs.config({ 
    enforceDefine: true, 
    paths: { 
     //declare path jquery, backbone, underscore,and other library here.... 
     "jquery-menu-aim" : "libs/jquery/jquery.menu-aim", 
     "bootstrap" : "libs/jquery/bootstrap.min" 
    }, 
    shim: { 
     "jquery-menu-aim" : { 
     deps: ["jquery"] , 
     exports: "Jquerymenuaim" 
     }, 
     "bootstrap" : { 
     deps: ["jquery"] , 
     exports: "Bootstrap" 
     } 
    } 
}); 

错误:未捕获的错误:没有明确呼吁jQuery的菜单,旨在 http://requirejs.org/docs/errors.html#nodefine require.js:8 未捕获的错误:没有定义呼吁引导 http://requirejs.org/docs/errors.html#nodefine

当我在我的看法中定义它。我想也许我在Shim配置中定义库时是错误的,但我无法在Google中找到它。

任何帮助,将不胜感激。谢谢。

回答

4

Bootstrap的垫片绝对是错误的,因为Bootstrap没有定义一个名为Bootstrap的符号。以下是我使用的:

bootstrap: { 
    deps: ["jquery"], 
    exports: "jQuery.fn.popover" 
}, 

jQuery.fn.popover方法是Bootstrap定义的方法。如果在RequireJS加载Bootstrap之后它不存在,这肯定表示Bootstrap尚未加载。

jquery.menu-aim的填充程序同样是错误的。看看the code,我看到它是一个jQuery插件。你应该改变你的shim来检查它添加到jQuery的函数。 jQuery.fn.menuAim看起来很不错。

+0

很好,感谢路易斯。但你怎么知道引导程序导出是jQuery.fn.popover? – Nothing

+0

我已阅读Bootstrap的代码。另一种解决方法是阅读文档并选择一个你正在使用的插件(Bootstrap充当插件)的方法。因此,如果文档说插件创建了一个名为“jQuery.foo”的新方法,那么您需要检查“jQuery.fn.foo”。 ''.fn''是必须的,因为这是存储jQuery对象上可用的方法的地方。 – Louis

+0

真的很有用的意见!谢谢! – seoyoochan

相关问题