我试图在RequireJS中使用Bootbox,但是每次出现此错误时:
ReferenceError:未定义引导框
我用依赖项配置了RequireJS:
var
bowerLocal = "../../../bower_components/",
asstsLocal = "../../assets/";
requirejs.config({
    paths: {
        "jquery": bowerLocal + "jquery/dist/jquery.min",
        "jquery.bootbox": bowerLocal + "bootbox/bootbox",
        "jquery.bootstrap": bowerLocal + "bootstrap/dist/js/bootstrap.min",
        "jquery.elevateZoom": bowerLocal + "elevatezoom/jquery.elevateZoom-2.2.3.min",
        "jquery.maskedInput": bowerLocal + "jquery-maskedinput/dist/jquery.maskedinput.min"
    },
    /**
     * Define as dependências de bibliotecas.
     */
    shim: {
        "jquery.bootstrap": {
            deps: ["jquery"]
        },
        "jquery.elevateZoom": {
            deps: ["jquery"]
        },
        "jquery.maskedInput": {
            deps: ["jquery"]
        },
        "jquery.bootbox": {
            deps: ["jquery", "jquery.bootstrap"],
            exports: 'bootbox'
        }
    }
});
require(
    ["jquery", "jquery.bootstrap", "jquery.bootbox", "jquery.maskedInput", "jquery.elevateZoom"],
    function (util) {
bootbox.alert("Hi");
}
...发布于 2014-04-28 06:02:32
在AMD模式下,在窗口上没有定义引导框,您必须自己定义它,所以在执行下面的操作之后,它现在可以工作了。
define(["bootbox"], function(bootbox){
 bootbox.alert("Hello Bootbox");
});当然,路径是在require.config()中定义的,这是可行的。
发布于 2014-11-19 15:14:27
我认为在@Pushker的回答中,他输入了define,实际上他想输入require
require(["bootbox"], function(bootbox) {    bootbox.alert("Hello Bootbox"); });
(他还将}错误地输入为{。
此外,当有多个依赖项时,还应该将这些参数指定为require中函数的参数,并确保它们与字符串数组参数的顺序相同。例如:
require(["jquery", "jquery.bootstrap", "jquery.bootbox", ...],     function(jquery, bootstrap, bootbox, ...) {        bootbox.alert("Hi");     } ... });
查看我的小提琴以获得一个实用的Bootbox示例:http://jsfiddle.net/bartvanderwal/L1emr4up/
https://stackoverflow.com/questions/22841625
复制相似问题