gpt4 book ai didi

javascript - 编译 ejs 时出现意外标记 ';'

转载 作者:行者123 更新时间:2023-12-04 09:31:39 27 4
gpt4 key购买 nike

我目前正在使用 sqlite 开发网络应用程序。在这里,我想根据数据库中注册的类型显示严重的数据。因此我想使用案例陈述。但是这个在调用它时在我看来提供了这个错误。

我还尝试在没有 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)

这是我的 View 代码:

<%- 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': %>
...

关于javascript - 编译 ejs 时出现意外标记 ';',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62814825/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com