使来自 GetJson 数组的循环数据成为链接
Making the Looped Data from GetJson Array a Link
我有一个问题,我正在为我的谷歌地图上的标记制作一个列表,但我希望它创建一个链接,该链接将显示列表中的值,它由getJson循环,<li>
仅在循环时附加。
有人可以帮我把它做成一个提醒值的链接吗?
这是我的代码集:
<script type="text/javascript">
var geocoder;
var map;
//var mgr;
function initialize() {
var minZoomLevel = 4;
var zooms = 7;
geocoder = new google.maps.Geocoder();
map = new google.maps.Map(document.getElementById('map'), {
zoom: minZoomLevel,
center: new google.maps.LatLng(38.50, -90.50),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
// Bounds for North America
var strictBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(15.70, -160.50),
new google.maps.LatLng(68.85, -55.90)
);
// Listen for the dragend event
google.maps.event.addListener(map, 'dragend', function () {
if (strictBounds.contains(map.getCenter())) return;
// We're out of bounds - Move the map back within the bounds
var c = map.getCenter(),
x = c.lng(),
y = c.lat(),
maxX = strictBounds.getNorthEast().lng(),
maxY = strictBounds.getNorthEast().lat(),
minX = strictBounds.getSouthWest().lng(),
minY = strictBounds.getSouthWest().lat();
if (x < minX) x = minX;
if (x > maxX) x = maxX;
if (y < minY) y = minY;
if (y > maxY) y = maxY;
map.setCenter(new google.maps.LatLng(y, x));
});
// Limit the zoom level
google.maps.event.addListener(map, 'zoom_changed', function () {
if (map.getZoom() < minZoomLevel) map.setZoom(minZoomLevel);
});
codeAddress();
}
var iconBase = 'https://maps.google.com/mapfiles/kml/shapes/';
function codeAddress() {
var infowindow = new google.maps.InfoWindow();
$.getJSON('/Dashboard/LoadWorkerList', function (address) {
$.each(address, function () {
var currVal = this["AddressLine1"];
geocoder.geocode({ 'address': currVal }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var marker = new google.maps.Marker({
map: map,
icon: iconBase + 'man.png',
position: results[0].geometry.location,
title: currVal
})
$('#places').append($('<li/>')
.text(currVal)
.data('location', results[0].geometry.location));
google.maps.event.addListener(map, 'bounds_changed', function () {
$('#places li').css('display', function () {
return (map.getBounds().contains($(this).data('location')))
? ''
: 'none';
});
});
//mgr = new MarkerManager(map);
google.maps.event.addListener(marker, 'click', (function (marker, i) {
return function () {
infowindow.setContent(currVal);
infowindow.open(map, marker);
}
})(marker, currVal));
address.push(marker);
}
else if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
setTimeout(codeAddress, 2000);
}
else {
alert("Geocode was not successful for the following reason: " + status);
}
});
});
google.maps.event.trigger(map, 'bounds_changed');
});
}
window.onload = function () {
initialize();
}
</script>
负载工人列表:
public JsonResult LoadWorkerList()
{
var workerList = new List<Worker_Address>();
// check if search string has value
// retrieve list of workers filtered by search criteria
var list = (from a in db.Worker_Address
where a.LogicalDelete == false
select a).ToList();
List<WorkerAddressInfo> wlist = new List<WorkerAddressInfo>();
foreach (var row in list)
{
WorkerAddressInfo ci = new WorkerAddressInfo
{
ID = row.ID,
Worker_ID = row.WorkerID,
AddressLine1 = row.Address_Line1 + " " + row.Address_Line2+ " " +row.City + " "+ GetLookupDisplayValById(row.State_LookID),
LogicalDelete = row.LogicalDelete
};
wlist.Add(ci);
}
return Json(wlist.ToList().OrderBy(p => p.AddressLine1), JsonRequestBehavior.AllowGet);
}
以下行:
$('#places').append($('<li/>')
应该改变。/ 前面的>应移除:
$('#places').append($('<li>')
如果带有 ID 位置的列表可用,您将获得地址列表。
相关文章:
- 添加数据属性及其值以使用纯javascript进行链接
- 向Graph中的所有d3.js数据点添加唯一链接
- 如何获取网站所有页面的链接以进行数据抓取
- 使用 IP 地址和超链接对数据表进行排序
- 如何在数据表的命令链接中使用 ajax 禁用表单字段
- 从chrome扩展创建一个包含POST数据的链接
- 如何分配数据切换=“;下拉菜单”;用于wordpress中的父链接
- 信息没有'点击AngularJS中的链接后不会刷新.I'我得到了{{value}},但没有得到数据
- 想要使用链接将数据发送到另一个视图
- 显示表格数据的更多链接
- 主干网+jquery:如何从与主干网的链接中检索数据's路由器
- 单击指向外部网站的链接后,通过MySQL保存数据
- 从页面上点击的链接中删除数据,然后移动到下一页&在CasperJS中重复
- 将.js文件中的数据包含到链接中
- JS:数据href中指定的链接在转盘中不起作用
- 将表单元格数据转换为单独.js文件中的内部链接
- href javascript 链接中的数据绑定值
- 使来自 GetJson 数组的循环数据成为链接
- 在哪里操作通过 AJAX 服务获得的数据?链接 fn 或控制器
- 轨道:找不到文件“提前输入.js”.直到我删除“数据涡轮链接”