[英]JQuery - jquery .append() produces “Cannot read property 'nodeName' of null”
I am trying to make a table of listings. 我正在尝试列出清单。 I have a variable that contains all the listings necessary called myListingsArray.
我有一个包含所有必要列表的变量,称为myListingsArray。 I want to loop through the array, outputting 5 or less listings at a time.
我想遍历数组,一次输出5个或更少的列表。 Each listing needs to have it's own properties.
每个列表都需要具有自己的属性。 Here's what I have so far:
这是我到目前为止的内容:
HTML: HTML:
<script type="text/template" id="listingsTemplate">
<div class-"listingsDiv">
<h1 class="listingsTitle">My listings</h1>
<table id="listingsTable">
<tr>
<th>Address</th>
<th>MLS</th>
<th>Broker</th>
<th>Price</th>
</tr>
</table>
</div>
</script>
JS: JS:
$(document).ready(function(){
$("#listingsLink").click(function(){
var personalTotal = myListingsArray.length;
$(".content").html("");
var template = $("#listingsTemplate").html();
$(".content").html(template);
for(var i = 0; i < personalTotal; i++){
appendListing(i, "#listingsTable");
}
});
});
function appendListing(i, location){
/*$(location).append( "
<tr>
<td id=\"address\">" + myListingsArray[i].address + "</td>
<td id=\"mls\">" + myListingsArray[i].mls + "</td>
<td id=\"broker\">" + myListingsArray[i].broker + "</td>
<td id=\"price\">" + myListingsArray[i].price + "</td>
</tr>
");*/ //EDIT: EASIER EXAMPLE
$(location).append(i);
}
When I run the code above, it returns an error saying 'Cannot read property "nodeName" of null'. 当我运行上面的代码时,它返回一个错误,提示“无法读取null的属性“ nodeName”。 "#listingsTable" clearly exists before the function is called so I don't understand why it throws an error.
在调用函数之前,“#listingsTable”显然存在,所以我不明白为什么会引发错误。
Please help Thank you 请帮忙谢谢
Well, I took a little break, came back, ran my code again and it suddenly worked. 好吧,我休息了一会儿,回来,再次运行我的代码,它突然起作用了。 I refreshed it a thousand times before and it didn't but for some reason now it does.
我之前刷新了一千次,但没有,但是由于某种原因,现在可以了。 Sorry to bother, have a good day everyone!
抱歉打扰,大家好!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.