Let's say that I got the following json object:
var jsonResult = {
"result": [
{ "UserName": "joga", "FirstName": "Jonas", "LastName": "G" }
{ "UserName": "sss", "FirstName": "Abra", "LastName": "p" }
]
};
I got an array with:
var cols = ["UserName", "LastName"];
how do I go through the json object and build a string only using the specified columns.
guessing game:
var rows = '<tr>';
$.each(jsonResult.result, function(jsonKey, jsonValue) {
$.each(cols, function(i,columnName) {
rows += '<td>' + jsonValue.attr(columnName) + '</td>';
});
});
Can anyone show me working code? ;)