当对来自Gdoc的可排序表使用list.js和tabletop时,在list.js的第一行出现错误:“未捕获的TypeError:无法读取未定义的属性'childNodes'”。
因为我工作的网站只能上传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);
最佳答案
问题
当dom具有var userList = new List('tablesetter', options);
类的元素时,应执行list
;由于在问题的代码中,list
类默认为list"
,因此此类元素应为<tbody class="list">
,仅当#tablesetter
函数从Google接收数据时才将其添加到showInfo
。
解决方案
我们确保var userList = new List('tablesetter', options)
语句在showInfo
函数之后(即:在末尾)执行;换句话说,将var userList = new List('tablesetter', options);
从options.js
移到showinfo
函数右右括号的前面。
更多细节
在list.js
尝试init()
的问题代码中,dom是:
当list.list
定义undefined
函数时,list.js
仍为getItemSource()
:
使用建议的修复程序,在var userList = new List('tablesetter', options);
上,dom类似于:
当定义了它的getItemSource()
函数时,list.list
可以使用tbody
作为方面:
关于javascript - list.js可排序表错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26262076/