简体   繁体   English

如何在流星js(0.9.2.2)模板中插入外部javascript文件

[英]How to insert external javascript files in meteor js (0.9.2.2) template

I am using following code to insert javascript files in template : 我正在使用以下代码在模板中插入javascript文件:

 _.each([
    "/assets/global/plugins/jquery-1.11.0.min.js",

    "/assets/global/plugins/jquery-migrate-1.2.1.min.js",

    "/assets/global/plugins/jquery-ui/jquery-ui-1.10.3.custom.min.js",
    "/assets/global/plugins/bootstrap/js/bootstrap.min.js",
    "/assets/global/plugins/bootstrap-hover-dropdown/bootstrap-hover-dropdown.min.js",
    "/assets/global/plugins/jquery-slimscroll/jquery.slimscroll.min.js",
    "/assets/global/plugins/jquery.blockui.min.js",
    "/assets/global/plugins/jquery.cokie.min.js",
    "/assets/global/plugins/uniform/jquery.uniform.min.js",
    "/assets/global/plugins/bootstrap-switch/js/bootstrap-switch.min.js"


], function(script, ready) { jQuery.getScript(script, function (data, textStatus, jqxhr){

    console.log( data ); // Data returned
    console.log( textStatus ); // Success
    console.log( jqxhr.status ); // 200
    console.log( "Load was performed." );

    })
});

I am getting following results (only one sample out of 10), all 10 files showing success messages : 我得到以下结果(十分之一),所有10个文件都显示成功消息:

(function(){var t=[].slice;!fu"[…] admin.js:63
"success" admin.js:64
200 admin.js:65

"Load was performed."

But when I see "View Generated Source" in Firefox developer tool, I can't see any inserted JavaScript files in html code. 但是,当我在Firefox开发人员工具中看到“查看生成的源代码”时,看不到html代码中插入的任何JavaScript文件。 Can some one guide me what I am doing wrong and how it can be rectified. 有人可以指导我做错了什么以及如何纠正。

The code works fine for me. 该代码对我来说很好。 jQuery.getScript() does not seem to change anything in the DOM, it simply runs the code virtually. jQuery.getScript()似乎并没有改变DOM中的任何内容,它只是虚拟地运行代码。 Try adding a file that has console.log('test'); 尝试添加具有console.log('test');的文件console.log('test'); as its contents. 作为其内容。

By the way, in your posted code, you are loading jQuery using jQuery's own function. 顺便说一句,在您发布的代码中,您正在使用jQuery自己的函数加载jQuery。 For this jQuery must already be loaded. 为此,jQuery必须已经加载。 It seems that you need to rethink how you are loading your scripts. 似乎您需要重新考虑如何加载脚本。

Why do you using ajax calls? 为什么使用ajax调用?

Did you know, Meteor merges head Tags of all html files. 您知道吗,Meteor合并了所有html文件的head标签。 So you can make as example a 'scripts.html' File with content: 因此,您可以制作一个包含内容的'scripts.html'文件作为示例:

<head>
<script src=...
</head>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM