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,920
    Thanks
    56
    Thanked 547 Times in 544 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,396
    Thanks
    12
    Thanked 569 Times in 562 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,920
    Thanks
    56
    Thanked 547 Times in 544 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
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 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
    •