简体   繁体   English

Javascript 和 Google 表格交互

[英]Javascript and Google sheets interactions

I'm new in JavaScript and currently building a web apps that interact with Google Sheets as a database.我是 JavaScript 新手,目前正在构建一个与 Google 表格作为数据库交互的网络应用程序。 Basically what i'm building right now is to get input from users through Web apps and giving it to the Google Sheets (which have all the database & formulas in it).基本上,我现在正在构建的是通过 Web 应用程序从用户那里获取输入并将其提供给 Google 表格(其中包含所有数据库和公式)。

Based on the input, Google sheets will then do the calculation and return back the value to JavaScript to be publish on the Web.根据输入,Google 表格将进行计算并将值返回给 JavaScript 以在 Web 上发布。 (I do this because i want to make the Google Sheets data remain private). (我这样做是因为我想让 Google 表格数据保持私密性)。 Due to the complex dataset, Google Sheet will take some time (around 3-5 seconds) before can pass the value to Javascripts (using SuccessHandler).由于数据集复杂,Google Sheet 需要一些时间(大约 3-5 秒)才能将值传递给 Javascripts(使用 SuccessHandler)。

The code that i currently have is working ok.我目前拥有的代码工作正常。 But i want to make the Web apps more interactive.但我想让 Web 应用程序更具交互性。 What i means is that, during the data processing by the Google Sheets, i want to tell the user to 'hold on' and don't do anything yet.我的意思是,在谷歌表格的数据处理过程中,我想告诉用户“坚持”,不要做任何事情。 I try to use loader but I don't know how to trigger & to stop the loader (while waiting Google Sheets do the calculation process).我尝试使用加载器,但我不知道如何触发和停止加载器(等待 Google Sheets 进行计算过程)。

Would greatly appreciate if someone could help me in this problem.如果有人能帮助我解决这个问题,将不胜感激。

thanks.谢谢。

Most of the time retrieving data from somewhere else using JavaScript is an asynchronous process.大多数情况下,使用 JavaScript 从其他地方检索数据是一个异步过程。 As a result you're not blocking the user from performing actions to keep your site interactive.因此,您不会阻止用户执行操作以保持站点的交互性。

The thing you're trying to achieve is keeping track of when your asynchronous data has been collected.您要实现的目标是跟踪收集异步数据的时间。 This can be achieved with Promises and techniques like async ... await.这可以通过 Promise 和诸如 async ... await 之类的技术来实现。 Another option, though not recommended, is making your code synchronous, meaning the whole page get blocked while your retrieving data from Google Sheets.另一种选择(虽然不推荐)是使您的代码同步,这意味着在您从 Google 表格检索数据时整个页面都会被阻止。 The pro is that a user can't do anything, the con is that if it takes too long it might look like the page stopped working (as it will literally freeze).优点是用户不能做任何事情,缺点是如果时间太长,页面可能看起来停止工作(因为它实际上会冻结)。

Explaining asynchronous JavaScript is a too in-depth topic to elaborate on here, but there are a lot of tutorials out there to get the hang of this.解释异步 JavaScript 是一个过于深入的主题,无法在这里详细说明,但是有很多教程可以掌握这一点。 I'd suggest you dive into that.我建议你深入研究。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM