从 AJAX 在 JavaScript 中创建一个列表
create a list in javascript from AJAX
嗨,我有一个函数,可以从 XML 数据中获取信息并在谷歌地图上打印标记我的问题是我想在一点到另一点之间创建一条路径这是检索数据
的代码 `
$.ajax({
type:"POST",
url:"PipeServlet?op=1",
dataType:"xml",
success: function(xml){
// Parses the data from xml
var newLat, newLon, newDesc,newName;
$(xml).find("deal").each(function(){
newName = $(this).find("name").text();
newLat = $(this).find("lat").text();
newLon = $(this).find("lon").text();
newDesc = $(this).find("desc").text();
// Displaying the Coupons on the map
marker = new google.maps.Marker({
position: new google.maps.LatLng(newLat,newLon),
map: map,
title: newName,
html: newDesc,
animation: google.maps.Animation.DROP
});`
所以我想将我检索的日期添加到列表中并绘制一条线,如下所示的代码:
mapLine = new google.maps.Polyline({map : map,
strokeColor : '#ff0000',
strokeOpacity : 0.6,
strokeWeight : 4,
path:[new google.maps.LatLng(33.240547551860935,35.6153623373566),new google.maps.LatLng(33.240009149357576,35.61381738496402)]
});`
我希望以动态方式创建path:[new google.maps.LatLng(33.240547551860935,35.6153623373566),new google.maps.LatLng(33.240009149357576,35.61381738496402)]
行 感谢您的帮助
构建一个数组: var path = new Array();
并在其末尾添加您的对象:path.push(position);
$.ajax({
type:"POST",
url:"PipeServlet?op=1",
dataType:"xml",
success: function(xml){
// Parses the data from xml
var newLat, newLon, newDesc,newName;
var path = new Array();
$(xml).find("deal").each(function(){
newName = $(this).find("name").text();
newLat = $(this).find("lat").text();
newLon = $(this).find("lon").text();
newDesc = $(this).find("desc").text();
var position = new google.maps.LatLng(newLat,newLon);
path.push(position);
// Displaying the Coupons on the map
marker = new google.maps.Marker({
position: position,
map: map,
title: newName,
html: newDesc,
animation: google.maps.Animation.DROP
});
...
});
mapLine = new google.maps.Polyline({map : map,
strokeColor : '#ff0000',
strokeOpacity : 0.6,
strokeWeight : 4,
path:path
});
...
相关文章:
- 从javascript创建一个列表
- 使用jquery从列表项中移除类,并将一个类添加到另一个列表项中
- 为数组Jquery/Javascript创建一个列表函数
- JavaScript,如何从一个列表中获取选定的值,同时在另一个列表中进行更改
- 如何在选择另一个列表框值时清除列表框值
- Angular2从数组创建一个列表
- 为什么此脚本仅应用于此列表中的一个列表项
- Jquery幻灯片中的列表,连接第一个和最后一个列表元素以创建旋转木马
- 如何从有序列表中选择一个列表元素
- 雄辩的Javascript:练习:一个列表
- 将单元格的高度从一个表列表指定到另一个列表
- AngularJS图像在点击时应该显示一个列表
- 从 AJAX 在 JavaScript 中创建一个列表
- 如何使用列表框的一个值来设置另一个列表框的值
- 在两个或多个 UL 列表之间切换,如果单击一个列表,则其他列表会自动以初始状态返回,就像从未单击过一样
- Jquery UI 可排序和可删除 - 无法将项目从一个列表克隆到另一个列表
- 使用 JQuery 将元素从一个列表移动到另一个列表
- 我有一个列表显示 1、2、3 个数字,我可以将它们转换为乌尔都语吗?
- 一个列表的Mailchimp多个订阅表单
- jQuery - 一个列表中的每个列表在另一个列表之前