我正在努力将谷歌电子表格中的数据转换为HTML页面。标题显示很好,但数据不存在。我已公开发布电子表格。我不知道为什么我没有看到任何数据。任何反馈或帮助都将不胜感激。
<h2>Construction and Infrastructure</h2>
<p>
<script type="text/javascript">// <![CDATA[
function importGSS(json) {
// Edit below //
var headers = ["Program Name", "Description", "Status", "Timeline"];
var gsxdata = ["gsx$projectname.$t", "gsx$description.$t", "gsx$status.$t", "gsx$timeline.$t"];
// Edit above //
$('#dataList').empty();
var headerData = '';
var rows = '';
for (i = 0; i < headers.length; i++) {
headerData += '<th>' + headers[i] + '</th>';
for (j = 0; j < gsxdata.length; j++) {
rows += '<tr>' + gsxdata[j] + '</tr>';
}
}
$('#dataList').append('<table id="tableDataList"><thead><tr>' + headerData + '</tr></thead><tbody>' + rows + '</tbody></table>');
var d = new Date(json.feed.updated.$t);
$('#updated').append('Updated: ' + d);
}
// ]]></script>
</p>
<div id="dataList"></div>
<div id="updated" style="text-align: right;"></div>
<p>
<script src="http://spreadsheets.google.com/feeds/list/1o07oxTjuJSIbZbnlUPvxhid98vdK7PGnSr36nOybbJ8/1/public/values?alt=json-in-script&callback=importGSS" type="text/javascript"></script>
<script type="text/javascript">// <![CDATA[
$(document).ready(function () {
var viewID = $("[id*='**']").attr('id');
var goTo = document.getElementById(viewID);
goTo.scrollIntoView(true);
});
// ]]></script>
答案 0 :(得分:1)
我通过添加一些代码来解决这个问题 - 我没有在我的codig中使用json.feed.entry,当我添加它时它起作用。
遵循更新的代码 -
<h2>Construction and Infrastructure</h2>
<p>
<script type="text/javascript">// <![CDATA[
function importGSS(json) {
// Edit below //
var headers = ["Project Name", "Description", "Status", "Timeline"];
var gsxdata = ["gsx$projectname", "gsx$description", "gsx$status", "gsx$timeline"];
// Edit above //
$('#dataList').empty();
var headerData = '';
var rows = '';
for (i = 0; i < headers.length; i++) {
headerData += '<th>' + headers[i] + '</th>';
}
for (i = 0; i < json.feed.entry.length; i++) {
entry = json.feed.entry[i];
rows += '<tr>';
for (j = 0; j < gsxdata.length; j++) {
if (entry.hasOwnProperty(gsxdata[j])) {
gdata = entry[gsxdata[j]].$t;
rows += '<td>' + gdata + '</td>';
}
}
rows += '</tr>';
}
$('#dataList').append('<table id="tableDataList"><thead><tr>' + headerData + '</tr></thead><tbody>' + rows + '</tbody></table>');
var d = new Date(json.feed.updated.$t);
$('#updated').append('Updated: ' + d);
}
// ]]></script>
</p>
<div id="dataList"></div>
<div id="updated" style="text-align: right;"></div>
<p>
<script src="http://spreadsheets.google.com/feeds/list/1o07oxTjuJSIbZbnlUPvxhid98vdK7PGnSr36nOybbJ8/1/public/values?alt=json-in-script&callback=importGSS" type="text/javascript"></script>
<script type="text/javascript">// <![CDATA[
$(document).ready(function () {
var viewID = $("[id*='**']").attr('id');
var goTo = document.getElementById(viewID);
goTo.scrollIntoView(true);
});
// ]]></script>
</p>