Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-18-2011, 05:59 AM   PM User | #1
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 453 Times in 451 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
can I convert an object name into a variable?

... 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:
Code:
$.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:

Code:
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...
xelawho is offline   Reply With Quote
Old 08-18-2011, 07:36 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
Code:
$.each( data[bizId], function(i, m) {
devnull69 is offline   Reply With Quote
Users who have thanked devnull69 for this post:
xelawho (08-18-2011)
Old 08-18-2011, 04:55 PM   PM User | #3
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 453 Times in 451 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
... could have sworn I tried that. thanks!
xelawho is offline   Reply With Quote
Old 08-19-2011, 03:54 AM   PM User | #4
jeffharris
New to the CF scene

 
Join Date: Jun 2011
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
jeffharris is an unknown quantity at this point
use eval
jeffharris is offline   Reply With Quote
Old 08-19-2011, 04:00 AM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,172
Thanks: 59
Thanked 3,994 Times in 3,963 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Quote:
Originally Posted by jeffharris View Post
use eval
Ugh. Never. Not if there's a way around it.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:31 PM.


Advertisement
Log in to turn off these ads.