EJS形式丢失space后的数据
Loss data after space in EJS form
有一个带有表单的 EJS 文件,其中有一个 <select>
下拉列表。
<form action="/scheduler/jobEvent" method="POST">
<div class="form-group">
<select class="custom-select" id="addJobEvent" name="event[title]">
<option selected>Select</option>
<!-- populate personnel list -->
<% personnelList.forEach(person => { %>
<option value=<%- person.title %>><%- person.title %></option>
<% }) %>
</select>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-outline-success">Save Event</button>
</div>
</form>
列表是从数据库中动态填充的。点击提交将表单数据发送到后端JS文件,进一步处理:
router.post('/scheduler/jobEvent', middleware.loggedAsAdmin, async (req,res) => {
var personTitle = req.body.event.title;
console.log(personTitle);
});
该列表列出了人们的昵称,由名字和姓氏的首字母组成,例如
John H, Mike K
,等等。我发现在从表单传输到后端时,space 之后昵称中的所有内容都丢失了。即 John H
在 JS 中 console.log 时缩短为 John
。以下是我的故障排除:
- 在渲染EJS文件时,昵称在space后的字母正确显示在列表中,因此所有数据都从DB传输到
<%- person.title %>
。
- 我在列表中硬编码了昵称,即
<option value='John H'><%- person.title %></option>
,它以同样的方式进入后端文件,所以客户端和服务器端之间没有任何损失。
- 我在数据库中的昵称中添加了下划线,即
John_H
并且它可以正常工作而不会丢失,也就是说它与 space.
有某种关系
有人遇到过这样的问题吗?
提前谢谢你。
比较工作代码和non-working代码:
<option value=<%- person.title %>>
和
<option value='John H'>
有什么不同?
引用
如果属性值没有引号,则 space 结束值 并且 space 之后的内容开始 新属性.
有一个带有表单的 EJS 文件,其中有一个 <select>
下拉列表。
<form action="/scheduler/jobEvent" method="POST">
<div class="form-group">
<select class="custom-select" id="addJobEvent" name="event[title]">
<option selected>Select</option>
<!-- populate personnel list -->
<% personnelList.forEach(person => { %>
<option value=<%- person.title %>><%- person.title %></option>
<% }) %>
</select>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-outline-success">Save Event</button>
</div>
</form>
列表是从数据库中动态填充的。点击提交将表单数据发送到后端JS文件,进一步处理:
router.post('/scheduler/jobEvent', middleware.loggedAsAdmin, async (req,res) => {
var personTitle = req.body.event.title;
console.log(personTitle);
});
该列表列出了人们的昵称,由名字和姓氏的首字母组成,例如
John H, Mike K
,等等。我发现在从表单传输到后端时,space 之后昵称中的所有内容都丢失了。即 John H
在 JS 中 console.log 时缩短为 John
。以下是我的故障排除:
- 在渲染EJS文件时,昵称在space后的字母正确显示在列表中,因此所有数据都从DB传输到
<%- person.title %>
。 - 我在列表中硬编码了昵称,即
<option value='John H'><%- person.title %></option>
,它以同样的方式进入后端文件,所以客户端和服务器端之间没有任何损失。 - 我在数据库中的昵称中添加了下划线,即
John_H
并且它可以正常工作而不会丢失,也就是说它与 space.
有某种关系 有人遇到过这样的问题吗?
提前谢谢你。
比较工作代码和non-working代码:
<option value=<%- person.title %>>
和
<option value='John H'>
有什么不同?
引用
如果属性值没有引号,则 space 结束值 并且 space 之后的内容开始 新属性.