'var'为 null 或不是对象
该代码在 Firefox 中运行良好,但在 IE8 中不行。我收到错误:“地址”为空或不是对象。
已经用谷歌搜索好几天了,无法得到关于如何修复/调试这个问题的明确答案。希望 stackoverflow.com 能够提供帮助。
var latlng = [
{
address: new GLatLng(-6.1364941,106.8000411),
marker0: myIcon0
},
{
address: new GLatLng(-6.1364941,106.8000411),
marker0: myIcon0
},
{
address: new GLatLng(1.3520831,103.8198361),
marker0: myIcon0
},
{
address: new GLatLng(14.06666671,121.33333331),
marker0: myIcon
},
];
var markers = [];
for ( var i = 0; i < latlng.length; i++ )
{
var marker = new GMarker( latlng[ i ].address, latlng[ i ].marker0 );
map.addOverlay( marker );
markers[i] = marker;
}
$(markers).each(function(i,marker){
GEvent.addListener(marker,"click", function(){
// map.panTo(marker.getLatLng());
map.setCenter(marker.getLatLng(), 10);
marker.openInfoWindowHtml($('.view-display-id-attachment_1 .views-row-'+(i+1)).html(), {maxWidth:200});
});
$("<li />")
.html($('.view-display-id-attachment_1 .views-row-'+(i+1)).html())
.click(function(){
map.setCenter(marker.getLatLng(), 10);
marker.openInfoWindowHtml($('.view-display-id-attachment_1 .views-row-'+(i+1)).html(), {maxWidth:200}); // custom balloon text
// alert($('.view-display-id-attachment_1 .views-row-'+(i+1)).html()); // VIEWS ROW COUNT DEBUG
})
.appendTo("#wtb-list");
});
The code works fine in Firefox, but not in IE8. I'm getting an error: 'address' is null or not an object.
Have been googling for days and couldn't get a clear answer on how to fix/debug this. Hope stackoverflow.com can help.
var latlng = [
{
address: new GLatLng(-6.1364941,106.8000411),
marker0: myIcon0
},
{
address: new GLatLng(-6.1364941,106.8000411),
marker0: myIcon0
},
{
address: new GLatLng(1.3520831,103.8198361),
marker0: myIcon0
},
{
address: new GLatLng(14.06666671,121.33333331),
marker0: myIcon
},
];
var markers = [];
for ( var i = 0; i < latlng.length; i++ )
{
var marker = new GMarker( latlng[ i ].address, latlng[ i ].marker0 );
map.addOverlay( marker );
markers[i] = marker;
}
$(markers).each(function(i,marker){
GEvent.addListener(marker,"click", function(){
// map.panTo(marker.getLatLng());
map.setCenter(marker.getLatLng(), 10);
marker.openInfoWindowHtml($('.view-display-id-attachment_1 .views-row-'+(i+1)).html(), {maxWidth:200});
});
$("<li />")
.html($('.view-display-id-attachment_1 .views-row-'+(i+1)).html())
.click(function(){
map.setCenter(marker.getLatLng(), 10);
marker.openInfoWindowHtml($('.view-display-id-attachment_1 .views-row-'+(i+1)).html(), {maxWidth:200}); // custom balloon text
// alert($('.view-display-id-attachment_1 .views-row-'+(i+1)).html()); // VIEWS ROW COUNT DEBUG
})
.appendTo("#wtb-list");
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题就在这里:
数组声明末尾的尾随逗号会给 IE8 带来问题,请将其删除:)其他浏览器...“忽略?”在大多数情况下,IE 总是会出错。
The issue is here:
that trailing comma at the end of your array declaration will give IE8 issues, remove it :) Other browsers..."overlook?" this in most cases, IE will always error on them.