我正在尝试将 bootbox ( http://bootboxjs.com ) 与 requirejs 一起使用。
main.html
<script>
var require = {
baseUrl: 'js',
paths: {
"jquery" :['jquery-1.11.0.min'],
"bootbox" :['bootbox.min'],
"bootstrap" :['//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min']
},
shim:
'bootstrap' :{deps:['jquery']},
'bootbox' :{deps:['bootstrap'],exports: 'bootbox'}
}
}
</script>
<script src="require.min.js"></script>
<script src="myscript1.js"></script>
main.js
define(['bootbox'],function(bootbox){
bootbox.alert("Hello world!"); // working properly
});
myscript1.js
require(['main'],function(){
bootbox.alert("Hello world!"); // not functioning (bootbox is not defined)
});
通常,一旦加载了 bootbox 插件,我们就可以在页面上的任何位置使用 bootbox:bootbox.alert("Hello world!");
当使用 requirejs 时,我必须在每次使用 requirejs 时传递bootbox
变量并定义它才能使用bootbox
. 我试过“出口”,但似乎没有帮助。
bootbox
加载后如何让变量全局可用?
谢谢你。