2016-03-30 44 views
0

我有這樣的代碼,我想要轉換爲本機JavaScript。什麼是最好的方法?

$.each(data.results, function (i, val) { 
    var venueObj = val.venue; 
    if ((venueObj && venueObj.lat != 0)) { 
     meetupName.push(val.name); 
     meetupDescript.push(val.description); 
     meetupUrl.push(val.event_url); 

     //meetupLat = []; 
     meetupLat.push(venueObj['lat']); 
     //meetupLong = []; 
     meetupLon.push(venueObj['lon']); 

     //address 
     meetupAddress.push(venueObj['address_1'] + "</h3><h3>" + venueObj['city']); 
    } else { 
     return; 
    }  
}); 
+3

'for循環.......'或'data.results.forEach(函數(){//} )' – Rayon

+0

爲循環是最好的主意.. –

+0

我嘗試,但我沒有得到我想要的價值。 – mmativ

回答

0

你應該省略 「迴歸」 在循環

for(var i in data.results) { 
    var val = data.results[i] 
    var venueObj = val.venue; 
    if ((venueObj && venueObj.lat != 0)) { 
     meetupName.push(val.name); 
     meetupDescript.push(val.description); 
     meetupUrl.push(val.event_url); 

     //meetupLat = []; 
     meetupLat.push(venueObj['lat']); 
     //meetupLong = []; 
     meetupLon.push(venueObj['lon']); 

     //address 
     meetupAddress.push(venueObj['address_1'] + "</h3><h3>" + venueObj['city']); 
    }  
} 
相關問題