加载两个脚本块(使用lab.js作为加载管理器)

Loading two script blocks (using lab.js as a load manager)

本文关键字:加载 js 管理器 lab 脚本 两个 使用      更新时间:2024-05-27

我试图在不同的地方加载lab.js的两个块,但如果我使用第一个块中加载的文件中的第二个块中的函数,它们将显示为未定义。

这是第一个块(从我的MVC项目加载到头模板中

<script>
$LAB
.script("<?php echo(GlobalConfig::$ROOT_URL); ?>scripts/jquery-1.10.2.min.js").wait()
.script("<?php echo(GlobalConfig::$ROOT_URL); ?>bootstrap/js/bootstrap.min.js").wait()
.script("<?php echo(GlobalConfig::$ROOT_URL); ?>bootstrap/js/bootstrap-datepicker.js").wait()
.script("<?php echo(GlobalConfig::$ROOT_URL); ?>scripts/libs/underscore-min.js").wait()
.script("<?php echo(GlobalConfig::$ROOT_URL); ?>scripts/libs/underscore.date.min.js").wait()
.script("<?php echo(GlobalConfig::$ROOT_URL); ?>scripts/libs/backbone-min.js").wait(function(){
    $(document).ready(function(){
        alert("loaded");
    });
});
</script>

这是在内容模板上加载的第二个块

$LAB
.script("../scripts/jquery-1.10.2.min.js").wait(function(){
    $(document).ready(function(){
        $(".test-badges").each(function( index ) {
            $( this ).tooltip({
              'show':true,
              'placement': 'bottom',
              'title' : 'Marca esta casilla si consideras que tu compañer@ debe responder igual.'
            });
        });
    });
});

第二个块中的函数(.toolkit)没有加载,因为它们是来自jquery的依赖项没有办法将两个块统一在一个加载在头中的块中(两个文件完全独立,并且都有动态创建的内容,这也不是我想要实现的)

所以问题是。。有没有办法告诉第二个块只在第一个块完全加载时加载?

非常感谢!

我认为问题是您正在创建两个独立的$LAB链,并且您想要的可以通过存储对$LAB链路的引用并将您的最后一个调用链接到末尾来实现,如下所示:

第一块:

<script>
var chain = $LAB
.script("<?php echo(GlobalConfig::$ROOT_URL); ?>scripts/jquery-1.10.2.min.js").wait()
.script("<?php echo(GlobalConfig::$ROOT_URL); ?>bootstrap/js/bootstrap.min.js").wait()
.script("<?php echo(GlobalConfig::$ROOT_URL); ?>bootstrap/js/bootstrap-datepicker.js").wait()
.script("<?php echo(GlobalConfig::$ROOT_URL); ?>scripts/libs/underscore-min.js").wait()
.script("<?php echo(GlobalConfig::$ROOT_URL); ?>scripts/libs/underscore.date.min.js").wait()
.script("<?php echo(GlobalConfig::$ROOT_URL); ?>scripts/libs/backbone-min.js")
</script>

第二块:

chain.wait(function(){
    $(document).ready(function(){
        $(".test-badges").each(function( index ) {
            $( this ).tooltip({
              'show':true,
              'placement': 'bottom',
              'title' : 'Marca esta casilla si consideras que tu compañer@ debe responder igual.'
            });
        });
    });
});