在面板上添加事件监听器

埃利亚斯·W

我有一个用例,我需要以编程方式添加/删除与面板关联的 onClick 事件。

我尝试了以下解决方案,但收到cijCell.addEventListener is not a function错误消息。

function cij_enabled(){
  var cijCell = app.pages.Home.descendants.cellFour;
  var index = cijCell.styles.indexOf('disabled-card');

  if (Report.riskOfLoss === 'High') {
    cijCell.styles.splice(index, 1);
    cijCell.addEventListener("click", function() {
      app.popups.Customer.visible = true;      
    });
  } else {
    if (index === -1){
      cijCell.styles.push('disabled-card'); 
      cijCell.removeEventListener("click", function() {
      app.popups.Customer.visible = true;      
    });
    }
  }
}

我怎样才能达到预期的结果?是否可以通过应用程序制造商以这种方式添加事件侦听器?

吗啡症

你绝对可以这样做,而且你几乎做对了。您唯一需要了解的是 appmaker 小部件不是本机 html 元素,因此会出现错误:

cijCell.addEventListener 不是函数

幸运的是,AppMaker 有一种方法可以获取与小部件关联的原生 html 元素。您需要使用该getElement()方法,然后才能使用添加/删除事件侦听器方法。所以你应该把你的代码从cijCell.addEventListener...改为cijCell.getElement().addEventListener...

参考:https : //developers.google.com/appmaker/scripting/api/widgets#Panel

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章