我從 Google 表格中獲取資料并將其顯示在 Google WebApp 前端。但問題是,除非重繪 視窗,否則 Google WebApp 前端不會自行更新。
有沒有辦法在檢測到 Google 表格中的資料更改或每 15 分鐘重繪 一次時自行重繪 。
索引.html
<script>
function onSuccess(UpdatedData) {
var div = document.getElementById('output');
div.innerHTML = '<div style="width: 6rem; ">Last Updated:</div> <span >' UpdatedData '</span>';
}
google.script.run.withSuccessHandler(onSuccess).getdata();
</script>
<body>
<div id="output"></div>
</body>
uj5u.com熱心網友回復:
如果您希望函式每 X 秒執行一次,您可以使用該setInterval方法。
例如,在您的腳本中:
<script>
function onSuccess(UpdatedData) {
var div = document.getElementById('output');
div.innerHTML = '<div style="width: 6rem; ">Last Updated:</div> <span >' UpdatedData '</span>';
}
setInterval(()=>{
google.script.run.withSuccessHandler(onSuccess).getdata()
},1e4)
</script>
<body>
<div id="output"></div>
</body>
這將使函式內部setInerval每 10 秒運行一次(10 秒 == 1e4,時間應該以毫秒為單位)。因此,為了每 15 分鐘重繪 一次,您應該使用9e5
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/432782.html
下一篇:一次下載多個檔案
