【问题标题】:Google Sheets Add-on onSelectionChange client sideGoogle 表格插件 onSelectionChange 客户端
【发布时间】: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


【解决方案1】:

有一个 onSelectionChange() 会在用户更改工作表上的选择时触发。

onSelectionChange()

但该更改没有客户端事件。

Event Objects

Simple Trigger

Installable Triggers

【讨论】:

  • 感谢您的回复。是的,我知道有这样的触发器,但我实际上在客户端需要它。
  • 有很多客户端事件,但不幸的是,这不是其中之一。
  • 实际上我没有找到任何客户端事件,你能告诉我在哪里可以找到文档吗?
  • 我在回答中添加了链接
  • 你说有很多客户端事件,但是链接里的都是服务器端事件,我错了吗?
猜你喜欢
  • 2021-08-17
  • 1970-01-01
  • 2015-08-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多