我想基于谷歌地图API实现一个地图,并添加一条基于坐标的路径。因此,我从我的模型中获取坐标,并希望迭代该对象以使用这些点填充地图。在我的jade模板中,我像这样包含API JS代码:
script(type='text/javascript')
function initialize() {
var myLatLng = new google.maps.LatLng(0, -180);
var myOptions = {
zoom: 3,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.TERRAIN
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var flightPlanCoordinates = [
- if (typeof(pins) != null)
- var.pins.forEach(function(pin) {
new google.maps.LatLng(pin.latitude, pin.longitude),
- })
new google.maps.LatLng(0,0)
];
var flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(map);
}
div#map_canvas(style='height: 500px; background-color: #990000;')
问题是:jade 渲染了这段片段
var flightPlanCoordinates = [
- if (typeof(pins) != null)
- var.pins.forEach(function(pin) {
new google.maps.LatLng(pin.latitude, pin.longitude),
- })
new google.maps.LatLng(0,0)
];
正如在jade模板源代码中那样... if等不会被解析!有什么想法吗?
谢谢!
var ok = #{someObjectOrNull} ? true : false
。此外,ok
将会是未定义的。相反,请使用 Peter Lyons 的方法!= "var ok = " + (user ? "true" : "false") + ";"
。 - fider