У меня есть функция, которая создает HTML-таблицу:Не удается прочитать свойство `parentNode` неопределенных
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 Я ожидаю его чтобы удалить всю строку, включая самую кнопку и немного текста, который возвращается. т.е.
hello [msgbutton]
goodbye [msgbutton]
Если я нажимаю [msgbutton] на приветствия подряд он будет выглядеть следующим образом:
goodbye [msgbutton]
, но до сих пор это: this.parentNode.parentNode.remove();
возвращается undefined ..
EDIT:
Я называю this.retrieveMatches()
в более раннем обещание this.fetchMatches() возвращает массив
retrieveMatches: function(){
var tableResult = this.makeHTMLMatchesTable(this.fetchMatches(object));
var matches = document.getElementById('matches')
matches.parentNode.insertBefore(tableResult, matches);
},
не могу показаться, чтобы воспроизвести это -> https://jsfiddle.net/1nhm2c4k/ – adeneo
@adeneo сделал правку включить еще один фрагмент кода, который я называю его от –
Можете ли вы показать 'obj.makeHTMLMatchesTable' и' obj.fetchMatches'? – Hydro