Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,981
    Thanks
    56
    Thanked 557 Times in 554 Posts

    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...

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    Code:
    $.each( data[bizId], function(i, m) {

  • Users who have thanked devnull69 for this post:

    xelawho (08-18-2011)

  • #3
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,981
    Thanks
    56
    Thanked 557 Times in 554 Posts
    ... could have sworn I tried that. thanks!

  • #4
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    use eval

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,198
    Thanks
    80
    Thanked 4,453 Times in 4,418 Posts
    Quote Originally Posted by jeffharris View Post
    use eval
    Ugh. Never. Not if there's a way around it.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •