SyntaxError:编译ejs时,“ views \ randomStrings.ejs”中出现意外标识符

时间:2019-12-18 19:05:34

标签: node.js ejs

我一直在获取此ejs unexpected identifier error,但仍无法纠正。

这是我的ejs文件:

<body>
    <main>
        <div class="allcontent" >
            <div class="classname">
                <h1>
                    <%= branch %>
                </h1>
                <h1>
                    <%= section %>
                </h1>
            </div>
            <div class="timer">
                <!-- put in timer code -->
            </div> 
            <div>
                <% if(length) { %>
                    <% randomStrings.forEach(string => { %>
                        <h3>
                            <%= string %>
                            <% setTimeout(function(let x+=1), 10000) %>
                        </h3>
                    <% }); %>
                <% } %>
            </div>

        </div>
    </main>
</body>

这是我的controller / randomStrings.js文件:

exports.getStrings = (req, res, next) => {
    const branch = 'CSE';
    const section = "C";
    const randomStrings = ["Blue", "Red", "Orange", "Yellow"];
    const length = 4;
    res.render('randomStrings', {
        path: '/',
        branch,
        section,
        randomStrings,
        length
    })
};

这是我收到的错误,我无法纠正它:

SyntaxError: Unexpected identifier in F:\Workspace\Attendance\views\randomStrings.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 (F:\Workspace\Attendance\node_modules\ejs\lib\ejs.js:626:12)
    at Object.compile (F:\Workspace\Attendance\node_modules\ejs\lib\ejs.js:366:16)
    at handleCache (F:\Workspace\Attendance\node_modules\ejs\lib\ejs.js:215:18)
    at tryHandleCache (F:\Workspace\Attendance\node_modules\ejs\lib\ejs.js:254:16)
    at View.exports.renderFile [as engine] (F:\Workspace\Attendance\node_modules\ejs\lib\ejs.js:459:10)
    at View.render (F:\Workspace\Attendance\node_modules\express\lib\view.js:135:8)
    at tryRender (F:\Workspace\Attendance\node_modules\express\lib\application.js:640:10)
    at Function.render (F:\Workspace\Attendance\node_modules\express\lib\application.js:592:3)
    at ServerResponse.render (F:\Workspace\Attendance\node_modules\express\lib\response.js:1012:7)

请帮助我纠正问题。

0 个答案:

没有答案