Appending rows into table from dictionary

784 views Asked by At

I have a dictionary with (key,value) inside my jquery success function,

$.each(myDictioary, function (key, value) {
    alert(key + ' is ' + value);
}

I want all the Dictionary values in a var So I can append it my table..I have tried this so far, which didn't help..

var row = "";
$.each(myDictioary, function (key, Value) {
    row+ = "<td>"+value+"</td>"
}); 
$("#tableBodyId")
    .append($('<tr>')                                       
    .append($('<td>').text(row))
  )

But I think I am doing something wrong when I'm concatenating <td>.

row+

Please let me know how I can get all values from dictionary into my var row..

1

There are 1 answers

0
charlietfl On BEST ANSWER

Several problems

The concatenation operator += should not have spaces in it.

You are creating an html string with multiple <td> in it but then appending a single <td> whose text is that html string

Try

var row = "";
$.each(myDictioary, function (key, Value) {
    row += "<td>"+value+"</td>"
}); 
var $tr = $('<tr>').append( row ); 
$("#tableBodyId").append($tr);

This assumes that you are only adding one row.

More details would need to be given if your dictionary contains data for more than one row