简体   繁体   English

sails.js ejs jquery包含麻烦

[英]sails.js ejs jquery include trouble

I think this may be duplicate'ish of 24510862/cannot-running-jquery-with-ejs-in-sails-js. 我认为这可能是重复的24510862 /不能运行-jquery-with-ejs-in-sails-js。

This is however a general inquiry with regards to asset linking and ejs views, it does not pertain to jQuery as such. 然而,这是关于资产链接和ejs视图的一般性查询,它不属于jQuery。 Please let me know what additional information is needed to trace the issue, and how to retrieve the log information if it's not trivial. 请让我知道跟踪问题需要哪些其他信息,以及如果日志信息不是微不足道的,如何检索日志信息。

I am building a sails.js application with some jQuery effects, but I think i may be doing the asset linking wrong. 我正在构建一个带有一些jQuery效果的sails.js应用程序,但我想我可能正在做错误的资产链接。 I created the project with --linker and dropped jquery.js in assets\\linker\\js folder. 我使用--linker创建了项目,并在assets \\ linker \\ js文件夹中删除了jquery.js。 I edited the gruntfile and moved the jQuery reference as adviced in other posts, and sails automatically adds it to layout.ejs as it should. 我编辑了gruntfile并按照其他帖子的建议移动了jQuery引用,并且sails会自动将它添加到layout.ejs中。 However, jQuery is not available to my ejs views. 但是,我的ejs视图无法使用jQuery。

This code works, but if I remove the explicit reference to jQuery it goes $ is not defined. 这段代码有效,但是如果我删除了对jQuery的显式引用,则$ $未定义。

\views\wizard\step1.ejs
----------------- 

<h1>Step 1 : Select Asset</h1>

<div id="step1container" class="container step1 wizpage">
Meh
</div> 

<script src="/linker/js/jquery.js"></script>

<script>
    $(document).ready(function() {
        $("#step1container").fadeIn(1000);
    });
</script>

Adding jQuery reference to all the ejs files seems wrong, shouldn't sails hookup what is needed for this scenario? 添加对所有ejs文件的jQuery引用似乎是错误的,不应该为这个场景需要传递什么? I found some articles suggesting to inject jquery manually using the EJS object, but that does not seem right either, shouldn't all ejs views generally have what is linked, available? 我发现一些文章建议使用EJS对象手动注入jquery,但这似乎也不正确,是不是所有的ejs视图通常都有链接的,可用的?

MANY thanks for any hints or suggestions 非常感谢任何提示或建议

现在通过从gruntfile中删除jquery引用并将其显式放在layout.ejs的header部分中来解决它。

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

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