简体   繁体   English

流星中的Javascript文件

[英]Javascript files in Meteor

So I have an app I'm working on, I've installed a few packages (namely twbs bootstrap, accounts and a few collections ones) and am starting to work on the way it looks. 因此,我有一个正在使用的应用程序,已经安装了一些程序包(即twbs引导程序,帐户和一些收集程序包),并且开始按照外观进行工作。 However, I'm trying to include a JS file that doesn't seem to be working. 但是,我试图包括一个似乎无法正常工作的JS文件。

Is there a good way to include js files, such as some jquery etc? 有没有很好的方法来包含js文件,例如jquery等? I've noticed both jquery and my js file are being loaded in the head but just don't seem to be working. 我注意到jquery和我的js文件都被加载到了头部,但是似乎没有用。 On my design (standard html page) the file is working fine, so the code isn't wrong. 在我的设计(标准html页面)上,文件工作正常,因此代码没有错。

I'm quite new with Meteor, so is there something I need to do with my routes or the way templates are loaded etc? 我对Meteor还是很陌生,所以我需要对路线或模板的加载方式做些什么?

Any help would be much appreciated! 任何帮助将非常感激! I've looked everywhere :( 我到处都看过:(

Tom. 汤姆

Try not to include scripts as you normally would via the <script> tag. 尽量不要像通常通过<script>标记那样包含脚本。 If I need a specific JS lib, my first step is to search on Atmosphere to see if someone else has wrapped it into a Meteor package. 如果需要特定的JS库,我的第一步是在Atmosphere上进行搜索,看看是否有人将它包装到Meteor包中。 If not, you can always just take the .js file (unminified) and drop it into a folder such as /client/lib/third-party and it should work fine. 如果没有,您总是可以将.js文件(最小化)放到/client/lib/third-party等文件夹中,并且应该可以正常工作。

Without more details such as which script you're trying to get working, or without seeing your code, this is the best help I can offer. 如果没有更多详细信息,例如您尝试使用的脚本,或者没有看到您的代码,这就是我能提供的最佳帮助。 Give the above a shot and see how that works out. 试一下上面的镜头,看看效果如何。

In Meteor all files are "preprocessed" . 在Meteor中,所有文件都经过“预处理” By default all JS files are loaded (and executed) on the Client and the Server. 默认情况下,所有JS文件都会在客户端和服务器上加载(并执行)。 This default locus is called common code. 该默认位置称为通用代码。 It is shared code between client and server. 它是客户端和服务器之间的共享代码。 Common CSS files are only loaded on the client. 通用CSS文件仅在客户端上加载。 Then there is client and server specific code. 然后是clientserver特定的代码。 These js files are saved in certain places. 这些js文件保存在某些位置。 client-side code is saved in /client , server side in /server . 客户端代码保存在/client ,服务器端保存在/server

This means that you'll want your code to be inside the /client directory. 这意味着您希望代码位于/client目录中。 You might call the file /client/main.js . 您可以将文件/client/main.js All Libraries included via packages (ex. jQuery) are available to these files. 通过软件包(例如jQuery)包含的所有库均可用于这些文件。

I'd also strongly recommend reading this before going forward. 我也强烈建议您在继续之前阅读此书。

PS: jQuery is in the Meteor-Core and is guaranteed to stay in there so you don't have to manually add it. PS:jQuery是在流星核心,并保证留在了那里,所以你不必手动添加。 There's no harm to it dough and it might be considered good style. 面团没有任何危害,它可以被认为是好的风格。

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

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