【发布时间】:2021-05-23 17:05:15
【问题描述】:
我正在为 Google 表格制作插件。我想在前端(在 javascript 端)收听一个在单元格选择更改时触发的事件。
因为我没有通过谷歌搜索问题找到任何解决方案。我想出了每 100 毫秒发出一次请求以检测选择是否已更改的想法。代码如下所示:
var lastSelection;
function onSelectionChange(e){
lastSelection = e ;
}
function onCheckSelection(e){
if(e != lastSelection){ // not the actual implementation
onSelectionChange(e);
}
}
setTimeout( function() {
google.script.run
.withSuccessHandler(onCheckSelection)
.getCurrentSelection(); // where getCurrentSelection is a server function that returns the range of currently selected cell
} , 100);
但我不确定是否有更好的主意。
【问题讨论】:
-
其实onSelectionChange触发器来自服务器
-
你能添加一些上下文吗?为什么在客户端需要这个? (不存在)
标签: google-apps-script google-sheets