<script type="text/javascript">
function InitMap(data) {
var map = new T.Map();
var arr = $.parseJSON(data);
//more code which renders the map
}
</script>
//partial view razor
@model System.Data.DataTable
@{
string strEvents = "[";
foreach (System.Data.DataRow row in Model.Rows)
{
strEvents += "[" + row["Lat"].ToString() + ", " + row["Long"].ToString() + ", " + "\"" +
row["Name"].ToString() + row["Case"].ToString() + "\"" + "],";
}
strEvents = strEvents.Remove(strEvents.LastIndexOf(","));
strEvents += "]";
}
//here i now need the code to call the above JS function InitMap passing in the JSON string 'strEvents' which renders the map.
<div id="map" class="map"</div>
我的问题是:当加载这个局部视图时,我希望直接渲染地图。上面我使用razor中的模型构造JSON字符串。然后我想在上面传递字符串并渲染地图的同一页面上调用JS函数。我不知道剃须刀怎么做?希望它尽可能清楚。