我正在迭代从服务器返回的集合;它看起来像这样:
roster: Array
0: Object
avatar: null
contactName: "me@test.com"
contactType: "grouping"
displayName: "Joe Shmoe"
我正在创建一个表并尝试将“displayName”添加到其中,但通过点符号访问不起作用。我下面的代码有什么问题?
function createAddressBook()
{
var tbl = document.getElementById( 'addressBook_tbl' );
var tbdy = document.createElement( 'tbody' );
// cells creation
for( var j = 0; j <= roster.length; j++ )
{
// table row creation
var row = document.createElement( "tr" );
for( var i = 0; i < 2; i++ )
{
// create element <td> and text node
//Make text node the contents of <td> element
// put <td> at end of the table row
var cell = document.createElement( "td" );
var cellText = document.createTextNode( roster[ j ].displayName );
cell.appendChild( cellText );
row.appendChild( cell );
}
//row added to end of table body
tbdy.appendChild( row );
}
// append the <tbody> inside the <table>
tbl.appendChild( tbdy );
}