这个函数运行良好。我在寻找什么如果有人更新 Google Sheet 上的数据而不重新加载网页,则更新任何语言的 DOM 元素帮助。我正在使用 googlesheet json 文件https://spreadsheets.google.com/feeds/list/1XaFRnQfNPRP86UPNcdgQuCCH6AeVe5FZOxBHaIPZDpM/od6/public/values?alt=jsonvar myData = [];// an example function that will get the data by index so it can be used however you wantfunction showDetails(index) { var selectedData = myData[index]; alert(JSON.stringify(selectedData, null, 2));}$.getJSON("https://spreadsheets.google.com/feeds/list/1XaFRnQfNPRP86UPNcdgQuCCH6AeVe5FZOxBHaIPZDpM/od6/public/values?alt=json", function(data) { myData = []; // reset whenever data loads var sheetData = data.feed.entry; var i; for (i = 0; i < sheetData.length; i++) { var dataPoint = { name: data.feed.entry[i]['gsx$slipno']['$t'], id: data.feed.entry[i]['gsx$id']['$t'], clientname: data.feed.entry[i]['gsx$clientname']['$t'], delivery: data.feed.entry[i]['gsx$delivery']['$t'] }; myData.push(dataPoint); // add data point to array to reference later // var email = data.feed.entry[i]['gsx$email']['$t']; // var delivery = data.feed.entry[i]['gsx$delivery']['$t']; document.getElementById('demo').innerHTML += ('<tr class="dd d-flex justify-content-around">' + '<td>' + " <span id='" + 't' + dataPoint.id + "'>" + dataPoint.name + '</span>' + '<span class="cn" onclick="showDetails(' + i + ');">' + dataPoint.clientname + '</span>' + '</td>' + '<td class="ml-auto gg" onclick="showDetails(' + i + ');">' + '</td>' + '</tr>'); } });
1 回答
芜湖不芜
TA贡献1796条经验 获得超7个赞
您可以循环运行该$.getJSON
函数setInterval
来轮询 Google 表格文档是否有更改。
下面将每秒检查一次更新
setInterval(function () {$.getJSON(.....)}, 1000)
添加回答
举报
0/150
提交
取消