【问题标题】:I have this error while compiling Ejs code编译 Ejs 代码时出现此错误
【发布时间】:2020-12-03 09:23:30
【问题描述】:

这里的obj是expressValidator的json解析文件

<%- include("partial/header") -%>

    <form method = "POST" action ="/">
        <% if(obj.name==="name1"){  %>
        <%= obj.msg =%>
        <% } %>
        <label> Name </label><br>
        <input type= "text" name ="name1">
        <br>
        <% if(obj.name==="place"){  %>
        <%= obj.msg =%>
        <% } %>
        <label> Place </label><br>
        <input type= "text" name ="place">
        <br>
        <% if(obj.name==="age"){  %>
        <%= obj.msg =%>
        <% } %>
        <label> Age </label><br>
        <input type= "text" name ="age">
        <br>
        <% if(obj.name==="time"){  %>
        <%= obj.msg =%>
        <% } %>
        <label> Time </label><br>
        <input type= "text" name ="time">
        <br>
        <div class="input-group">
  <div class="input-group-prepend">
    <span class="input-group-text" id="inputGroupFileAddon01">Upload</span>
  </div>
  <div class="custom-file">
    <input type="file" class="custom-file-input" id="inputGroupFile01"
      aria-describedby="inputGroupFileAddon01">
    <label class="custom-file-label" for="inputGroupFile01">Choose file</label>
  </div>
</div>
        <br>
        <input type="submit" value ="Submit">
    </form>

    <a class="button" href="/showelement">
    Show all elements</a>

<%- include("partial/footer") -%>

错误是

SyntaxError: Unexpected token ) in /workspace/TestValidExpress/views/index2.ejs

在编译 ejs 时

如果上述错误没有帮助,您可能想尝试 EJS-Lint: https://github.com/RyanZim/EJS-Lint 或者,如果您打算创建一个异步函数,请将 async: true 作为选项传递。

    at new Function (<anonymous>)
    at Template.compile (/workspace/TestValidExpress/node_modules/ejs/lib/ejs.js:661:12)
    at Object.compile (/workspace/TestValidExpress/node_modules/ejs/lib/ejs.js:396:16)
    at handleCache (/workspace/TestValidExpress/node_modules/ejs/lib/ejs.js:233:18)
    at tryHandleCache (/workspace/TestValidExpress/node_modules/ejs/lib/ejs.js:272:16)
    at View.exports.renderFile [as engine] (/workspace/TestValidExpress/node_modules/ejs/lib/ejs.js:489:10)
    at View.render (/workspace/TestValidExpress/node_modules/express/lib/view.js:135:8)

【问题讨论】:

    标签: javascript sql node.js syntax ejs


    【解决方案1】:

    问题是您在 ejs 标记内使用了两倍相等的 = 符号。
    要输出渲染值,请使用此 &lt;%= obj.msg %&gt; 表单,NOT &lt;%= obj.msg =%&gt;

    你可以阅读更多关于ejs标签here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-15
      • 1970-01-01
      • 2015-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多