我遍歷從服務器返回的集合;它看起來像這樣:通過點符號訪問對象屬性
roster: Array
0: Object
avatar: null
contactName: "[email protected]"
contactType: "grouping"
displayName: "Joe Shmoe"
我創建一個表,並試圖將「顯示名」添加到它,而是由點號訪問不能正常工作。我的代碼在下面有什麼問題?
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);
}
和我打賭,因爲你沒有使用'i'訪問它 – letiagoalves