gpt4 book ai didi

node.js - 使用node.js和mongoDB向map.jade文件(传单)添加标记

转载 作者:太空宇宙 更新时间:2023-11-04 02:24:26 25 4
gpt4 key购买 nike

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
});
});
};

这是node.js 文件,它使用for/each 循环渲染到jade 文件上,但不起作用

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: '&copy; <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);

但是没有循环,jade 文件可以完美运行

 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: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'}).addTo(map);
var marker = L.marker([#{list[0].lat},#{list[0].lon}]).addTo(map);

每次我尝试新的缩进或更改循环时都会发生“无法读取属性”错误,请期待您的回复

最佳答案

脚本之后的所有内容。从字面上看,它会被发送到您的 html 中,而 jade 构造将无法在那里工作。您可以使用常规的 javascript for 循环来迭代列表。如果它们不是基元,您还需要 JSON.parse 各个字段,因为插值在脚本标记中也不起作用。

关于node.js - 使用node.js和mongoDB向map.jade文件(传单)添加标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31366205/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com