antony
7/25/2014 10:04:00 PM
I'm struggling with the syntax when trying to create an array of objects.
I have a JSON feed which has a boat load of data in a don't need so I'm just grabbing the relevant values and creating a new array (it's to be using in a leaflet.js map btw)
The format I need is:
markers: {
marker-name-1:{"lat":32.0852999,"lng":34.7817676},
marker-name-2:{"lat":30.0444196,"lng":31.2357116}
}
Using:
var newArray = [];
feed = Datafeed.query(function (response){
_.each(response, function(rows) {
var latstr = rows.custom_fields._wp_geo_latitude;
var lngstr = rows.custom_fields._wp_geo_longitude;
var title = rows.title;
var result = {};
result [title] = {lat : latstr , lng : lngstr};
newArray.push(result);
});
});
I get:
{"marker-name-1":{"lat":"32.0852999","lng":"34.7817676"}},
{"marker-name-2":{"lat":"30.0444196","lng":"31.2357116"}}
They are all separate objects which won't work dammit!
Some help on how I can construct what I'm after would be much appreciated.
Thanks
Antony