简体   繁体   English

如何将静态.js文件添加到Meteor项目?

[英]How to add static .js files to Meteor project?

Sorry for my english. 对不起我的英语不好。 I have a functions.js file, where I put all my js code. 我有一个functions.js文件,我在其中放置了所有js代码。 The functions.js doesn't refer to Meteor. functions.js不涉及流星。 Where do I place the functions.js file so that it is attached to the template? 我应该在哪里放置functions.js文件,以便将其附加到模板上?

Thanks in advance. 提前致谢。

You may place any clients.js file somewhere into your ./client directory. 您可以将任何client.js文件放在./client目录中的某个位置。 This will be packed and loaded automatically by your app. 这将由您的应用自动打包和加载。

If you also need this functions on server, place ist into ./lib directory. 如果服务器上也需要此功能,请将ist放在./lib目录中。

Checkout the meteor guide about application structure. 查看有关应用程序结构的流星指南。

If you want to attach functions to a blaze template you can use helpers, events, oncreated ondestroyed onrendered etc. This is done in the client folder or imports for the client side. 如果要将功能附加到炽烈的模板,则可以使用帮助程序,事件,创建的ondestroyed的onrendered等。此操作在客户端文件夹中完成或在客户端导入。

In a file that is run on the client create a helper like the example below: 在客户端上运行的文件中,创建一个帮助器,如下例所示:

Template.myTemplate.helpers({
foo() {
return Session.get("foo");
}
});

In the example the helper can be invoked with {{foo}} in the template defined with 在示例中,可以使用{{foo}}在定义为

<template name="myTemplate">

Taken from the docs: http://docs.meteor.com/api/templates.html#Template-helpers 摘自文档: http : //docs.meteor.com/api/templates.html#Template-helpers

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

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