【发布时间】:2020-01-14 00:31:55
【问题描述】:
您好,我想在 ejs 中应用条件语句,但它在我的代码中不起作用“我希望当我选择特定值(不使用运输)时,按钮显示否则不显示,但仅显示 - (其他条件) 在开发人员工具中的每个下拉列表中的选择上",它显示了像 https://ibb.co/60ZWcXh 这样的条件语句代码,它没有采用
条件语句
<%if (locals.students == "noTransportation") { %>
<button type="button" class="btn btn-primary pull-right" onclick="" id="">
Migrate to Applicants
</button>
<%} else { %>
-
<% } %>
完成students_list.ejs
<select class="form-control changeDropDown" id="transportation">
<option value="applications">Applications</option>
<option value="transportation">Using Transportation</option>
<option value="noTransportation">Not Using Transportation</option>
<option value="All">All</option>
</select>
<%if (locals.students == "noTransportation") { %>
<button type="button" class="btn btn-primary pull-right" onclick="" id="">
Migrate to Applicants
</button>
<%} else { %>
-
<% } %>
控制器:
in controller the code in comments ////data migration code//// is for this conditional statement but its not working
paste.ofcode.org/RGu9t7Fm3uNPNKiczNP2p9
我该如何解决这个问题
【问题讨论】:
-
您是否尝试在发送之前在您的 JS 代码中 console.log
locals.students? -
js代码中的nthing
-
@matrixersp 它说未定义
-
这就是为什么它在else块中显示代码的原因,如果你想在if块中显示代码,你需要给
locals.students值“noTransportation” -
完成,但我希望当我选择不使用交通工具时,按钮会显示,否则不会显示,但每个选择都会显示按钮
标签: node.js express ejs node-modules