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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Using a string as a object attr name

    I'm trying to create a UI object that displays a list of JSON data being delivered through an AJAX request. Say the JSON is formatted like so:
    Code:
    {list:[{key:val},{key:val},{key:val}], date:'01/01/09' }
    For the purposes of reusing this UI element, the element should take the evaluated JSON object and a string for the root list node so that it knows which data to display. Something like this:
    Code:
    var data = eval(jsonString);
    var rootnode = 'list';
    
    var Example = function(data,rootnode) {
        for (item in data.rootnode) {
            // add 'item' to the html list
        }
    };
    In the code above, obviously 'rootnode' can't be used like it is. However, since the JSON is evaluated into an object, how can I use the value of 'rootnode' to access the correct attribute in data??
    Last edited by scott212; 12-29-2008 at 08:12 AM.

  • #2
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    In this situation it worked like this: data[rootnode]


  •  

    Posting Permissions

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