gpt4 book ai didi

javascript - Javascript 中的 ASP.NET MVC4 Razor。谷歌地图未加载

转载 作者:行者123 更新时间:2023-11-30 05:34:49 25 4
gpt4 key购买 nike

我在使用 setMarkers() 函数时遇到一些问题,我的 map 根本没有显示。我假设我在 setMarkers 函数中对 Razor 语法做错了什么。你能提出一个解决方案吗?由于我不是这项技术的专家,在 Javascript 函数中混合使用 Razor 是否正常,或者我应该遵循另一种更好的做法,即在 @section featured 范围内移动我的脚本函数?提前致谢

我的标记模型:

public class MarkerModel
{
public string Description { get; set; }
public double latitude { get; set; }
public double longitude { get; set; }
public int zIndex { get; set; }
}

我的看法:

@model IEnumerable<DAssistant.Web.Models.MarkerModel>

<style type="text/css">
#map-canvas
{
height: 500px;
}
</style>

@{
ViewBag.Title = "Map";
}

@section featured {
<div id="map-canvas"></div>
}

<script type="text/javascript" src="http://www.google.com/jsapi?autoload={'modules':[{name:'maps',version:3,other_params:''}]}"></script>
<script type="text/javascript">

function init() {
var mapDiv = document.getElementById('map-canvas');

var mapOptions = {
center: new google.maps.LatLng(-33.890542, 151.274856),
zoom: 8,
mapTypeControl: true,
zoomControl: true,
scaleControl: true,
streetViewControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
}

var map = new google.maps.Map(mapDiv, mapOptions);

setMarkers(map);
}

function setMarkers(map) {

@foreach (var item in Model)
{
<text>
var myLatLng = new google.maps.LatLng(@item.latitude, @item.longitude);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: @item.Description,
zIndex: @item.zIndex
});
</text>
}
}
google.maps.event.addDomListener(window, 'load', init);
</script>

最佳答案

改变这个:

title: @item.Description

收件人:

title: '@item.Description'

例如描述是'some string',那么标题就是:

title: some string

那不是有效的 javascript。

关于javascript - Javascript 中的 ASP.NET MVC4 Razor。谷歌地图未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24567552/

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