1

I have json as shown below

{
    "aaData": [
        [
            {
                "displayValue": "Home Page",
                "link": "http://somelink.com"
            },
            "London",
            "1983"
        ],
        [
            {
                "displayValue": "Backlog",
                "link": "http://BacklogApp.com"
            },
            "Paris",
            "1999"
        ]
    ]
}

Now in js, i am populating table using sAjaxSource. But I want first column to be a link. I am using fnRowCallback attribute to get data. Here I am checking if first element of the row is not a string (means is an array), then make first element as a link as I have done below

"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
                if(typeof aData[0] != 'string'){
                    $('td:eq(0)', nRow).html( '<a href="' + aData[0][1] +'" >'  +
                            aData[0][0] + '</a>');
                }
            }

But problem is I am not able to get aData[0][0] or aData[0][1] value as it shows undefined.

Does anyone know how can i get "displayValue" and "link" values here????

1
  • i got answer here in someone comment, but just that comment has been deleted. I dont know why.. :( Answer was to access the values as aData[0]['displayValue'] Commented Oct 4, 2012 at 12:16

2 Answers 2

3

This is if you are working with object that contains whole JSON. what you need depends on your aData content

var data = {
   "aaData": [
        [
             {  
                "displayValue":"Home Page",
                "link":"http://somelink.com"
         },
            "London",
            "1983"
        ],
        [
            {   
                "displayValue":"Backlog",
                "link":"http://BacklogApp.com"
         },
            "Paris",
            "1999"
        ]
    ]
}

than to access display value of the first displayValue:

data.aaData[0][0].displayValue
data.aaData[0][0].link
Sign up to request clarification or add additional context in comments.

Comments

0

i got answer here in someone comment, but just that comment has been deleted. I dont know why.. :( Answer was to access the values as aData[0]['displayValue']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.