【问题标题】:SyntaxError: Unexpected identifier in C:\Users\Ak\Desktop\todolist-v1\views\list.ejs while compiling ejsSyntaxError: Unexpected identifier in C:\Users\Ak\Desktop\todolist-v1\views\list.ejs 同时编译 ejs
【发布时间】:2020-07-25 06:47:25
【问题描述】:

使用EJS创建待办事项使用node js,express js。当我使用 EJS 的其他标签时,例如

错误:

SyntaxError: Unexpected identifier in C:\Users\Ak\Desktop\todolist-v1\views\list.ejs while compiling ejs

If the above error is not helpful, you may want to try EJS-Lint:
https://github.com/RyanZim/EJS-Lint
Or, if you meant to create an async function, pass `async: true` as an option.
    at new Function (<anonymous>)
    at Template.compile (C:\Users\Ak\Desktop\todolist-v1\node_modules\ejs\lib\ejs.js:661:12)
    at Object.compile (C:\Users\Ak\Desktop\todolist-v1\node_modules\ejs\lib\ejs.js:396:16)
    at handleCache (C:\Users\Ak\Desktop\todolist-v1\node_modules\ejs\lib\ejs.js:233:18)
    at tryHandleCache (C:\Users\Ak\Desktop\todolist-v1\node_modules\ejs\lib\ejs.js:272:16)
    at View.exports.renderFile [as engine] (C:\Users\Ak\Desktop\todolist-v1\node_modules\ejs\lib\ejs.js:489:10)
    at View.render (C:\Users\Ak\Desktop\todolist-v1\node_modules\express\lib\view.js:135:8)
    at tryRender (C:\Users\Ak\Desktop\todolist-v1\node_modules\express\lib\application.js:640:10)
    at Function.render (C:\Users\Ak\Desktop\todolist-v1\node_modules\express\lib\application.js:592:3)
    at ServerResponse.render (C:\Users\Ak\Desktop\todolist-v1\node_modules\express\lib\response.js:1012:7)

代码

 

     <% for (var i=0; i<new.ListItems.length; i++) { %> 
        <li><%= newListItems[i] %></li>
    <% } %>

【问题讨论】:

    标签: javascript node.js express ejs


    【解决方案1】:

    如果您的数组名称是newListItems,请将new.ListItems 更改为newListItems

       <% for (var i=0; i<newListItems.length; i++) { %> 
            <li><%= newListItems[i] %></li>
        <% } %>
    

    【讨论】:

    • 非常感谢,它成功了。我搜索了除数组名称之外的所有内容。我的错。
    猜你喜欢
    • 2023-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-06
    • 1970-01-01
    • 2021-06-09
    相关资源
    最近更新 更多