使用node.js将标记添加到map.jade文件(传单)&;蒙哥达
这是node.js文件,它使用for/each循环渲染到jade文件上,但不起作用使用node.js将标记添加到map.jade文件(传单)&;蒙哥达,node.js,mongodb,express,pug,leaflet,Node.js,Mongodb,Express,Pug,Leaflet,这是node.js文件,它使用for/each循环渲染到jade文件上,但不起作用 exports.Markermap = function(req, res) { var db = req.db; var collection = db.get('markers'); collection.find({},{},function(e,results){ res.render('markermap', { "list" : resu
exports.Markermap = function(req, res) {
var db = req.db;
var collection = db.get('markers');
collection.find({},{},function(e,results){
res.render('markermap', {
"list" : results,
vlat : req.params.lat,
vlon : req.params.lon
});
});
};
html
头
链接(rel='stylesheet',href='0)http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css')
身体
h1#标题GIS框架B4048270
#地图(style='height:700px;')
脚本(src=)http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js')
剧本
var map=L.map(“map”).setView([#{vlat},#{vlon}],13);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',{attributes:'©;contributors'}).addTo(map);
每个结果,我都在列表中
var marker=L.marker([#{results.lat},#{results.lon}]).addTo(map);
但如果没有环,玉锉就可以完美地工作
html
head
link(rel='stylesheet', href='http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css')
body
h1#title GIS Framework B4048270
#map(style='height: 700px;')
script(src='http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js')
script.
var map = L.map("map").setView([#{vlat},#{vlon}], 13);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'}).addTo(map);
each results,i in list
var marker = L.marker([#{results.lat},#{results.lon}]).addTo(map);
html
头
链接(rel='stylesheet',href='0)http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css')
身体
h1#标题GIS框架B4048270
#地图(style='height:700px;')
脚本(src=)http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js')
剧本
var map=L.map(“map”).setView([#{vlat},#{vlon}],13);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',{attributes:'©;contributors'}).addTo(map);
var marker=L.marker([#{list[0].lat},[#{list[0].lon}]).addTo(map);
每次我尝试新缩进或更改循环时,都会出现“无法读取属性”错误,请期待您在脚本之后的回复。从字面上说,它被发送到html中,而jade构造在那里不起作用。您可以使用常规javascript for循环来迭代列表。如果各个字段不是原语,您还需要对它们进行JSON.parse,因为在脚本标记中插值也不起作用。脚本后面的所有内容。从字面上说,它被发送到html中,而jade构造在那里不起作用。您可以使用常规javascript for循环来迭代列表。如果不同的字段不是原语,您还需要对它们进行JSON.parse,因为在脚本标记中插值也不起作用。thanyou。有没有关于如何实现javascript循环的建议?谢谢。有没有关于如何实现javascript循环的建议?
html
head
link(rel='stylesheet', href='http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css')
body
h1#title GIS Framework B4048270
#map(style='height: 700px;')
script(src='http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js')
script.
var map = L.map("map").setView([#{vlat},#{vlon}], 13);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'}).addTo(map);
var marker = L.marker([#{list[0].lat},#{list[0].lon}]).addTo(map);