...

View Full Version : can I convert an object name into a variable?



xelawho
08-18-2011, 05:59 AM
... at least that's what I think I'm trying to do...

what I have is this function which reads the JSON attributes of crab_house, a JSON object:

$.getJSON( '../map/clients.json', function(data) {
$.each( data.crab_house, function(i, m) {
bizAdd= new google.maps.LatLng(m.lat, m.lng);
var message =m.html;
createMarker(bizAdd,message);
});

but what I would like to do is something like:



var bizId='crab_house';

$.getJSON( '../map/clients.json', function(data) {
$.each( data.bizId, function(i, m) {
bizAdd= new google.maps.LatLng(m.lat, m.lng);
var message =m.html;
createMarker(bizAdd,message);
});

is it possible?

thanks in advance...

devnull69
08-18-2011, 07:36 AM
$.each( data[bizId], function(i, m) {

xelawho
08-18-2011, 04:55 PM
... could have sworn I tried that. thanks! :thumbsup:

jeffharris
08-19-2011, 03:54 AM
use eval

Old Pedant
08-19-2011, 04:00 AM
use eval

Ugh. Never. Not if there's a way around it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum