简体   繁体   中英

sails.js ejs jquery include trouble

I think this may be duplicate'ish of 24510862/cannot-running-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. 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. I created the project with --linker and dropped jquery.js in assets\\linker\\js folder. 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. However, jQuery is not available to my ejs views.

This code works, but if I remove the explicit reference to jQuery it goes $ is not defined.

\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? 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?

MANY thanks for any hints or suggestions

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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