I am trying to get data into a table with jquery. The data is in attributes and an array and I would need to go trough that array to extract the information that I require.
Using the following, I put some content into a array:
$(Stuff).find("desc").each(function(index) {
stuffArray[index]=$(this).text();
});
Here I put it into a table
$("#table").append('<td><a href="'+ siteRoot+'/'+item.url'"></a><td>'+item.title'</td><td开发者_如何转开发>' + stuffArray[i+1] + '</td>');
I am guessing that I should loop the stuffArray but I don't know how to do append things like that.
you should probably enclose the table construction in a for loop then. The structure is like:
for(var i = 0; i < stuffArray.length; i++) {
$("#table").append('<tr><td><a href="'+ siteRoot+'/'+item.url'"><td>'+item.title'</td><td>' + stuffArray[i+1] + '</td></tr>');
}
If you want to loop round the stuffArray and add the contents to the table you can do something like:
for(var x=0;x<stuffArray.length;x++){
$("#table").append('<tr><td>'+stuffArray[x]+'<td></td>'+stuffArray[x]+'</td></tr>');
}
see a stripped down example here
Update
In response to your comments:
You still want to loop round but rather than create a new row for each element in StuffArray, add a new <td>
element to the table, like:
var markup = '<tr>';
for(var x=0;x<stuffArray.length;x++){
markup += '<td>'+stuffArray[x]+'</td>';
}
markup+='</tr>';
$('#table').append(markup);
Updated Example
精彩评论