使用 EJS 渲染时的空白
Whitespace when rendering using EJS
我想将使用 EJS 呈现的对象传递给聚合物元素。
为什么我得到 addressLine1":"123" abc"
,空白字符有什么问题,有什么方法可以将对象传递到聚合物元素中而不像这样在 HTML 上暴露它。
EJS
<g-map customer=<%- JSON.stringify(customer) %> vehicles = <%= JSON.stringify(vehicles) %> ></g-map>
渲染后:
<g-map customer="{"_id":"5658013d7e6908d4b370c3f0","coordinates":[10.764221,106.656368],"phone":"09090909","addressLine1":"123" abc","email":"customer1@gmail.com"}="">
路由文件:
res.render('vehicles',
{
title: 'Vehicles Managerment',
customer : req.session.customer,
vehicles : body.data
});
客户对象
"customer": {
"_id": "5658013d7e6908d4b370c3f0",
"coordinates": [
12345,
12345
],
"addressLine1": "123 ABC",
"email": "customer1@gmail.com",
"username": "customer1@gmail.com"
}
经过研究,我发现我必须将渲染对象放在单引号中,这样它才能正确处理空格。
<g-map customer='<%- JSON.stringify(customer) %>' vehicles = '<%= JSON.stringify(vehicles) %>'
我想将使用 EJS 呈现的对象传递给聚合物元素。
为什么我得到 addressLine1":"123" abc"
,空白字符有什么问题,有什么方法可以将对象传递到聚合物元素中而不像这样在 HTML 上暴露它。
EJS
<g-map customer=<%- JSON.stringify(customer) %> vehicles = <%= JSON.stringify(vehicles) %> ></g-map>
渲染后:
<g-map customer="{"_id":"5658013d7e6908d4b370c3f0","coordinates":[10.764221,106.656368],"phone":"09090909","addressLine1":"123" abc","email":"customer1@gmail.com"}="">
路由文件:
res.render('vehicles',
{
title: 'Vehicles Managerment',
customer : req.session.customer,
vehicles : body.data
});
客户对象
"customer": {
"_id": "5658013d7e6908d4b370c3f0",
"coordinates": [
12345,
12345
],
"addressLine1": "123 ABC",
"email": "customer1@gmail.com",
"username": "customer1@gmail.com"
}
经过研究,我发现我必须将渲染对象放在单引号中,这样它才能正确处理空格。
<g-map customer='<%- JSON.stringify(customer) %>' vehicles = '<%= JSON.stringify(vehicles) %>'