我正在尝试在ejs模板的内部脚本标签内使用ejs标签。代码可以工作,但是“ vs code”仍然说存在“问题”,“ <%-”和“%>”是突出显示红色
<form action="/posts/<%=post.id %>?_method=DELETE" method="POST">
<button> delete </button>
</form>
//internal script
<script>
var post = <%- JSON.stringify(post) %> ;
mapboxgl.accessToken = 'pk.eyJ1IjoibWlsZXMtYmxhcSIsImEiOiJjazBld3NxZjEwam0wM2V0aTV0MmlreDQxIn0.rEo1aSdtmy8RL-wX4Ni3AA';
//setting up client side mapbox
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/light-v9',
center: post.coordinates,
zoom: 3
});
答案 0 :(得分:0)
您必须像这样修改post
变量的声明
var post = <%= JSON.stringify(post) %> ;