繁体   English   中英

意外的标记 ';' 在编译 ejs 时

[英]Unexpected token ';' while compiling ejs

我目前正在使用 sqlite 开发 web 应用程序。 在这里,我想根据在数据库中注册的类型显示严重的数据。 因此,我想使用 case 语句。 但是,在我看来,这个错误在调用它时给了我这个错误。

我也尝试在没有 case 语句的情况下显示它,并且显示得非常好。

SyntaxError: Unexpected token ';' in C:\Users\tu\Documents\SVAV3.1\views\show_config.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\tung\Documents\SmartVacAppV3.1\node_modules\ejs\lib\ejs.js:633:12)
    at Object.compile (C:\Users\tung\Documents\SmartVacAppV3.1\node_modules\ejs\lib\ejs.js:392:16)
    at handleCache (C:\Users\tung\Documents\SmartVacAppV3.1\node_modules\ejs\lib\ejs.js:215:18)
    at tryHandleCache (C:\Users\tung\Documents\SmartVacAppV3.1\node_modules\ejs\lib\ejs.js:254:16)
    at View.exports.renderFile [as engine] (C:\Users\tung\Documents\SmartVacAppV3.1\node_modules\ejs\lib\ejs.js:485:10)
    at View.render (C:\Users\tung\Documents\SmartVacAppV3.1\node_modules\express\lib\view.js:135:8)
    at tryRender (C:\Users\tung\Documents\SmartVacAppV3.1\node_modules\express\lib\application.js:640:10)
    at Function.render (C:\Users\tung\Documents\SmartVacAppV3.1\node_modules\express\lib\application.js:592:3)
    at ServerResponse.render (C:\Users\tung\Documents\SmartVacAppV3.1\node_modules\express\lib\response.js:1008:7)

这是我的观点的代码:

<%- include("layouts/_header") %>
<div class = "container" style="padding-top: 50px">

<div class="row">
    <form class="col-12" action="/create_config" method="POST">

        <% categories.forEach((category) => {%>
        <div class="card mb-4">
            <div class="card-header"> <%= category.name_var_category %> </div>
            <% data.forEach((values) => {%>
                <% if (values.id_variable_category === category.id) {%>  
                    <% switch(values.name_variable_types) {%>
                        <% case 'Hexadecimal': %>
                            <div class="form-group col-md-4">
                                <label for="<%= values.name_variable %>"><%= values.name_variable %></label>
                                <input type="text" class="form-control" name="<%=  values.name_variable %>" value="<%= values.value_variable %>">
                            </div>
                            <% break; %>
            
                        <% case 'Boolean': %>
                            <div class="form-group col-md-4">
                                <label for="<%=  values.name_variable %>"><%= values.name_variable %></label>
                                <select class="form-control" name="<%=  values.name_variable %>" id="<%=  values.name_variable %>">
                                    <option value="<%= values.value_variable %>"><%= values.value_variable %></option>
                                    <% if(values.value_variable === "ON") {%>
                                        <option value="<%= 'OFF' %>">OFF</option>
                                    <% }else {%>
                                        <option value="<%= 'ON' %>">ON</option>
                                    <% } %>
                                </select>
                            </div>
                            <% break; %>
            
                        <% case 'Integer': %>
                            <div class="form-group col-md-4">
                                <label for="<%=  values.name_variable %>"><%= values.name_variable %></label>
                                <input type="number" class="form-control"  name="<%=  values.name_variable %>" value="<%= values.value_variable %>" min="<%= values.start_range_variable %>" max="<%= values.end_range_variable %>" step="<%= values.step_variable %>" >
                            </div>
                            <% break; %>
            
                        <% case 'Float': %>
                            <div class="form-group col-md-4">
                                <label for="<%=  values.name_variable %>"><%= values.name_variable %></label>
                                <input type="number" class="form-control"  name="<%=  values.name_variable %>" value="<%= values.value_variable %>" min="<%= values.start_range_variable %>" max="<%= values.end_range_variable %>" step="<%= values.step_variable %>" >
                            </div>
                            <% break; %>
            
                        <% default: %>
                        <div class="alert alert-success">
                            <p>A value had no variable type</p>
                        </div>
                    <% } %>
                <% } %>
            <% }) %>
        </div>   
        <% }) %>

        <div class="form-group row">
            <div class="col-sm-10 pt-3">
                <button type="submit" class="btn btn-primary">Géréner Fichier Config</button>
            </div>
        </div>
    </form>
</div>
</div>
<%- include("layouts/_footer") %>

问题在于您如何使用switch case - 似乎 ejs 期望cases保留在switch -ejs 表达式中。 尝试这样的事情:

  <% switch(values.name_variable_types) {
        case 'Hexadecimal': %>
            <div class="form-group col-md-4">
              <label for="<%= values.name_variable %>"></label>
              <input type="text" class="form-control" name="<%=  values.name_variable %>" value="<%= values.value_variable %>">
            </div>
        <% break;
        case 'Boolean': %>
        ...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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