简体   繁体   English

jQuery-jquery .append()产生“无法读取null的属性'nodeName'”

[英]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.

相关问题 无法使用select2读取jQuery验证上未定义的nodeName属性 - Cannot read property of nodeName undefined on jQuery validation with select2 jQuery 1.5.1用敲出js嘶嘶声&#39;无法读取属性节点名&#39;子&#39;&gt;&#39;选择器 - jQuery 1.5.1 Sizzle 'cannot read property nodename' child '>' selector with knockoutjs 未捕获的类型错误:无法读取 null 的属性“nodeName” - Uncaught TypeError: Cannot read property 'nodeName' of null 未捕获的类型错误:无法在 jQuery 中读取 null 的属性“追加” - Uncaught TypeError: Cannot read property 'append' of null in jQuery Trumboqyg 所见即所得编辑器不适用于 Jquery.Validate 插件,“Uncaught TypeError: Cannot read property 'nodeName' of undefined” - Trumboqyg WYSIWYG editor does not work with Jquery.Validate plugin, "Uncaught TypeError: Cannot read property 'nodeName' of undefined" 无法读取 javascript 中 HTMLDocument.catchIt 中 null 的属性“nodeName” - Cannot read property 'nodeName' of null at HTMLDocument.catchIt in javascript VideoJS 错误 Uncaught TypeError: Cannot read property 'nodeName' of null - VideoJS error Uncaught TypeError: Cannot read property 'nodeName' of null jQuery AJAX .error产生错误“无法读取未定义的属性fieldErrors” - Jquery AJAX .error produces error “Cannot read property fieldErrors of undefined” 无法读取 null 的属性“getContext”(无 jQuery) - Cannot read property 'getContext' of null (no jQuery) jQuery无法读取null错误的属性 - Jquery cannot read property of null error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM