簡體   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