【问题标题】:Error with list.js sortable tablelist.js 可排序表出错
【发布时间】:2018-09-25 10:51:58
【问题描述】:

将 list.js 和 tabletop 用于从 Gdoc 获取的可排序表时,我在 list.js 的第一行收到错误:“Uncaught TypeError: Cannot read property 'childNodes' of undefined”。

因为我工作的网站只能上传JS,所以我需要用js或jquery编写我所有的html,所以有点不稳定。我认为由于我拥有所有东西的顺序而引发了错误,但我尝试移动东西无济于事。除排序外,一切正常。

谢谢!

HTML 文件

    <!DOCTYPE html>
   <html>
   <head>
      <link rel="stylesheet" type="text/css" href="styles.css">
    <script type="text/javascript" src="list.js-master/dist/list.min.js"></script>
      <script type="text/javascript" src="src/tabletop.js"></script>
      <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

</head>

<body>

<div id="tablesetter"></div>

 </body>

<script type="text/javascript">

var url = 'url to gdoc here';

$(document).ready( function(){
  Tabletop.init( {key: url, callback: showInfo, parseNumbers: true} )})

function showInfo(data, tabletop){

  $("#tablesetter").append('<h2>Table Working</h2><table><thead><th class="sort" data-sort="university">University</th><th class="sort" data-sort="no">Billionaires</th><th class="sort" data-sort="no2">Billionaires Rank</th><th class="sort" data-sort="rank">U.S. News Rank</th></thead><tbody class="list"></tbody></table>');


 $.each(tabletop.sheets("Sheet1").all(), function(i, cat){

    var htmltable = $('<tr><td class="university">' + cat.university + '</td>');
          htmltable.append('<td class="no">' + cat.numberofbillionaires + '</td>');
          htmltable.append('<td class="no2">' + cat.rankedbybillionaires + '</td>');
          htmltable.append('<td class="rank">' + cat.usnewsranking + '</td></tr>');
          htmltable.appendTo("tbody");
  })

}

</script>
  <script type="text/javascript" src="options.js"></script>


</html>

JS 文件

var options = {
  valueNames: [ 'university', 'no' , 'no2' , 'rank']
};

var userList = new List('tablesetter', options);

【问题讨论】:

    标签: javascript jquery html listjs


    【解决方案1】:

    问题

    var userList = new List('tablesetter', options); 应该在 dom 具有 list 类的元素时执行;因为在问题的代码中 list 类默认为 list" ,所以这样的元素应该是 &lt;tbody class="list"&gt; ,只有当 showInfo 函数从谷歌接收数据时才会附加到 #tablesetter

    解决办法

    我们确保var userList = new List('tablesetter', options) 语句在showInfo 函数之后(即:结束)执行;换句话说,将var userList = new List('tablesetter', options);options.js 移动到showinfo 函数的右右括号之前。

    更多详情

    list.js 尝试init() 时的问题代码中,dom 是: list.js 定义它的getItemSource() 函数时,list.list 仍然是undefined

    使用建议的修复程序,在 var userList = new List('tablesetter', options); 的 dom 就像:

    当定义它的 getItemSource() 函数时,list.list 可以使用 tbody 作为方面:

    【讨论】:

      【解决方案2】:

      如果您查看这篇文章,我敢肯定您只是缺少 list.js 正常运行的一些最低要求。尝试使用 id 和“搜索”类以及其他类动态添加输入。让我知道这是否有帮助。

      https://stackoverflow.com/a/23078200/4812515

      【讨论】:

        猜你喜欢
        • 2015-11-21
        • 2020-01-12
        • 1970-01-01
        • 2013-06-03
        • 2015-07-19
        • 2017-10-10
        • 2013-12-29
        • 2016-07-27
        • 2011-01-08
        相关资源
        最近更新 更多