0
我想popoulate使用Firebug API一個二維數組,填充二維數組在JS
var sites = [];
var siteCounter = 0;
//Firebase API Calls
var messageListRef = new Firebase('https://my.firebaseio.com');
messageListRef.once('value', function(allMessagesSnapshot) {
allMessagesSnapshot.forEach(function(messageSnapshot) {
var latitude = messageSnapshot.child('latitude').val();
var longitude = messageSnapshot.child('longitude').val();
sites[siteCounter][0] = 'siteCounter';
sites[siteCounter][1] = latitude;
sites[siteCounter][2] = longitude;
sites[siteCounter][3] = siteCounter;
sites[siteCounter][4] = 'This is siteCounter.';
siteCounter++;
alert(sites[siteCounter][1] + " " + sites[siteCounter][2]);
});
});
但是,這打破了網站[siteCounter] [0],並說,這是不確定的。任何線索如何使用這個?
問題是我失去了foreach循環之外的所有值 – CodeMonkey
你確定嗎?因爲在這個例子中,我寫了jsFiddle,我不會失去我的價值http://jsfiddle.net/UdD2L/ –