我有一个创建 HTML 表的函数:
makeHTMLTable: function(array){
var table = document.createElement('table');
for (var i = 0; i < array.length; i++) {
var row = document.createElement('tr');
var cell = document.createElement('td');
cell.textContent = array[i];
row.appendChild(cell);
cell = document.createElement('td');
var msgButton = document.createElement('button');
msgButton.setAttribute("id", "msgButton" +i);
msgButton.textContent = "message";
msgButton.addEventListener("click", this.messageUser, false);
cell.appendChild(msgButton)
row.appendChild(cell);
table.appendChild(row);
}
return table;
},
然后我有这个功能:
messageUser: function(){
debugger;
this.parentNode.parentNode.remove();
unMatch();
},
当我单击 msgbutton 时,我希望它删除整行,包括按钮本身和返回的一点点文本。IE:
hello [msgbutton]
goodbye [msgbutton]
如果我单击 hello 行上的 [msgbutton],它将如下所示:
goodbye [msgbutton]
但到目前为止:this.parentNode.parentNode.remove();
返回未定义..
编辑:
我调用this.retrieveMatches()
了之前的承诺 this.fetchMatches() 返回一个数组
retrieveMatches: function(){
var tableResult = this.makeHTMLMatchesTable(this.fetchMatches(object));
var matches = document.getElementById('matches')
matches.parentNode.insertBefore(tableResult, matches);
},