开发者

Accessing JSON value results in undefined

开发者 https://www.devze.com 2023-03-18 22:38 出处:网络
I have the following JSON structure: { \"headers\":[ {\"title\": \"Action\", \"width\": 3, \"class\": \"centeralign\"},

I have the following JSON structure:

{

"headers":[
        {"title": "Action", "width": 3, "class": "centeralign"},
        {"title": "ID", "width": 4, "class": "leftAlign"},
        ..
        ..
    ],
"rows": [
            {"cells": [
                {"data": "Edit", "width": 3, "class": "centeralign"},
                {"data": "030194"},
                ..
                ..
           ]}
        ]
}

For every "data" in JSON, I'm dynamically generating a table cell. This is what I have:

$.each(response.rows, function(index, rows){

    $("tr#columnData").append("<td>" + rows.cells.data +开发者_如何学运维 "</td>");
});

rows.cells.data is resulting in "undefined".

What am I doing wrong?


cells is an array in your JSON structure, so you need to loop through it:

$.each(response.rows, function(index, row) {
    $.each(row.cells, function() {
        $('tr#columnData').append('<td>' + this.data + '</td>');
    });
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号