Sails.js - How to inject a js file to a specific route?

前端 未结 5 854
天涯浪人
天涯浪人 2020-12-13 07:39

For example, I have a page /locations/map which I need to include Google Map library, and include a .js file (e.g. location.js) specif

5条回答
  •  温柔的废话
    2020-12-13 08:14

    I discover other way to do that

    In MapController.js

    // you can add as many as you like
    res.locals.scripts = [
      '//maps.googleapis.com/maps/api/js',
    ];
    return res.view();
    

    In layout.ejs

    
    
    
    
    <% if (scripts) { %>
        <% for (i = 0; i < scripts.length; i++) { %>
            
        <% } %>
    <% } %>
    

提交回复
热议问题