Use Object.prototype.forEach to replace the common for loop.
This commit is contained in:
37
index.html
37
index.html
@@ -87,28 +87,33 @@ function mapInit(){
|
|||||||
.done(function(json){
|
.done(function(json){
|
||||||
//response json are now in the json variable
|
//response json are now in the json variable
|
||||||
console.log(json);
|
console.log(json);
|
||||||
var events = json.events;
|
json.events.forEach(function(ev, i) {
|
||||||
for (var i = events.length - 1; i >= 0; i--) {
|
var geo = ev.geo.split(' ');
|
||||||
var geo = events[i].geo.split(' ');
|
|
||||||
var marker = new AMap.Marker({
|
var marker = new AMap.Marker({
|
||||||
map: mapObj,
|
map: mapObj,
|
||||||
position: new AMap.LngLat(geo[1], geo[0]),
|
position: new AMap.LngLat(geo[1], geo[0]),
|
||||||
// icon: events[i].owner.alt.match('site') ? new AMap.Icon({
|
// icon: ev.owner.alt.match('site') ? new AMap.Icon({
|
||||||
// image: events[i].owner.avatar,
|
// image: ev.owner.avatar,
|
||||||
// }) : null,
|
// }) : null,
|
||||||
title: events[i].title + '\n' +
|
title: ev.title + '\n' +
|
||||||
events[i].address.replace(/上海(\s+|市)/g, '') + '\n' +
|
ev.address.replace(/上海(\s+|市)/g, '') + '\n' +
|
||||||
events[i].begin_time.substring(5, events[i].begin_time.length - 3) + ' ~ ' +
|
ev.begin_time.substring(5, ev.begin_time.length - 3) + ' ~ ' +
|
||||||
events[i].end_time.substring(5, events[i].end_time.length - 3)
|
ev.end_time.substring(5, ev.end_time.length - 3)
|
||||||
});
|
});
|
||||||
|
|
||||||
AMap.event.addListener(marker, 'click', function(marker_, i_) {
|
// closure based
|
||||||
return function() {
|
// AMap.event.addListener(marker, 'click', function(marker_, i_) {
|
||||||
// marker_.setContent(events[i_].content);
|
// return function() {
|
||||||
window.open(events[i_].alt,'mywin','');
|
// // marker_.setContent(json.events[i_].content);
|
||||||
};
|
// window.open(json.events[i_].alt,'mywin','');
|
||||||
}(marker, i));
|
// };
|
||||||
};
|
// }(marker, i));
|
||||||
|
|
||||||
|
AMap.event.addListener(marker, 'click', function() {
|
||||||
|
// marker_.setContent(ev.content);
|
||||||
|
window.open(ev.alt,'mywin','');
|
||||||
|
});
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.fail(function() {
|
.fail(function() {
|
||||||
alert('Can not use douban api');
|
alert('Can not use douban api');
|
||||||
|
|||||||
Reference in New Issue
Block a user