将JQuery添加到meteor并无误地编写 [英] Adding JQuery to meteor and writing it without errors

查看:37
本文介绍了将JQuery添加到meteor并无误地编写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 JQuery 列表包添加到meteor 并且它可以识别它.但是,当我在应用程序主 html 文件的 <script></script> 标记中内联编写 JQuery 代码时,它无法识别它(但我没有收到错误消息).当我在我的流星应用程序 .js 文件中编写 JQuery 代码时,我收到一个错误.所以我很困惑,一旦添加了 javascript 或添加的库包(如 JQuery),我应该如何编写它们.谢谢.

I added the JQuery list package to meteor and it recognizes it. But when I write JQuery code inline in <script></script> tags in the apps main html file it does not recognize it ( but I don't get an error). When I write JQuery code in my meteor app .js file I get an error. So I am confused as to how one is suppose to write with javascript or added library packages (like JQuery) once they are added. Thank you.

推荐答案

您需要将通用 javascript 放入容器中,以将其包含在特定的 Meteor 模板中.

You need to put general javascript in a container to include it in a specific Meteor template.

对于您可能习惯的一般 onLoad 脚本,您可以在呈现模板后将该代码封装在一个函数中示例:

For general onLoad scripts that you might be used to, you can encapsulate that code inside a function once the template is rendered Example:

Template.*templatename*.rendered = function()
{
    //do this only on template load
    if(!this._rendered) {this._rendered = true;console.log('Template onLoad');}
    //everything outside if is done every time the template is re-drawn (meteor sends an update)
}

这篇关于将JQuery添加到meteor并无误地编写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆