I have a result set returning from a service that gives me the following json
{
\"ThreadCount\":61,
\"GroupList\":[
{\"userName\":\"KLT\",\"count
When I've used $.each() I have used a function(i, item), where i is an integer indicating index, and item is the actual object. That is how the documentation shows it being done -- the method is described as function callback(indexInArray, valueOfElement).
Inside the function provided to each
, this
refers to the current element. Try this:
$.each(result.GroupList, function() {
$('#myTable > tbody').append(
'<tr><td>'
+ this.userName
+ '</td><td>'
+ this.count +
'</td></tr>'
);
});
If that doesn't work for you, it may have something to do with this: $('#myTable > tbody')
, considering that there is no tbody
element. I believe that Internet Explorer will automatically create one but the other browsers won't. Check $.support.tbody to see if the browser does that for you.
I noticed your table does not actually have a tbody element. This could be part of your issue.
$('#myTable > tbody').append.....
<table id="myTable" border="2" cellpadding="3" cellspacing="3">
</table>
I would also suggest that you create a string in your $.each() loop and then do the following after your each loop:
$('#myTable > tbody').html(string);
This will reduce the overhead of appending each time you iterate over the array.