按钮点击触发两次

huangapple go评论56阅读模式
英文:

Button click firing twice

问题

我已经构建了一个Outlook插件,并希望为它添加一个新功能,但问题是我添加的新按钮在点击时触发两次 - 在taskpane.js或taskpane.html中没有重复的按钮名称或重复的事件侦听器。

以下是按钮的代码片段:

document.getElementById("generate-email-button").addEventListener("click", function () {
  var recipientType = document.getElementById("new-email-recipient-type").value;
  var emailType = document.getElementById("email-type").value;
  var emailContent = document.getElementById("email-content").value;
  var emailTone1 = document.getElementById("emailTone1").value;
  var emailTone2 = document.getElementById("emailTone2").value;
  
  generateSuggestedEmail(recipientType, emailType, emailContent, emailTone1, emailTone2);
});

控制台告诉我,taskpane.js和由webpack生成的js文件都在注册点击事件:

d47f4b55d6e75be28dfc.js:797 generateSuggestedEmail called
taskpane.js:721 generateSuggestedEmail called

但是没有其他函数或按钮会像这样被调用两次。我找不到根本原因,想知道是否有人有这方面的经验或有解决方法?

我期望的是按钮点击只注册一次。我尝试找到重复的事件侦听器,但没有我自己创建的重复事件侦听器 - 显然在d47f4b55d6e75be28dfc.js中有一个,但这是由webpack从我的代码中生成的,所以没有办法在不从我的代码中删除它的情况下将其删除。

英文:

I have built an outlook addin, and I wanted to add on feature to it, the problem I'm having the new button I added it firing twice on click - there is no duplicate button name or duplicate event listener in taskpane.js or taskpane.html

here is the code snippet for the button:

    document.getElementById("generate-email-button").addEventListener("click", function () {
      var recipientType = document.getElementById("new-email-recipient-type").value;
      var emailType = document.getElementById("email-type").value;
      var emailContent = document.getElementById("email-content").value;
      var emailTone1 = document.getElementById("emailTone1").value;
      var emailTone2 = document.getElementById("emailTone2").value;
      
      generateSuggestedEmail(recipientType, emailType, emailContent, emailTone1, emailTone2);
    });

The console tells me that both taskpane.js and the js file made by the webpack are registering the click

d47f4b55d6e75be28dfc.js:797 generateSuggestedEmail called
taskpane.js:721 generateSuggestedEmail called

but no other function or button gets called twice like that. I can't find the root cause of this, wondering if any of you have any experience with this or have a workaround?

What I'm expecting to happen is the button click only registers once. I have tried finding the duplicate event listener there is none that I create - there obviously is one in d47f4b55d6e75be28dfc.js but that is created by the webpack from my code, so there is no way to remove that without removing it from my code.

答案1

得分: 1

只需将其中一个文件添加到输出文件夹即可。很可能是你的webpack配置错误,导致它们同时添加到了dist文件夹中。我建议清空dist文件夹,然后重新构建解决方案。你只需将一个*.js文件添加到dist文件夹中。

另外,要移除之前在Windows、Mac或iOS上预览加载的插件,你需要清除计算机上的Office缓存。此外,如果你对插件清单进行了更改(例如,更新图标的文件名或添加命令的文本),你应该清除Office缓存,然后使用更新后的清单重新预览加载插件。这样做可以让Office按照更新后的清单描述来呈现插件。详见清除Office缓存以获取更多信息。

英文:

There is no need to include both files to the output folder. Most probably you have webpack improperly configured to include them both to the dist folder. I'd suggest clearing the dist folder and building the solution anew. You need to include only one *.js file to the dist folder.

Also to remove an add-in that you've previously sideloaded on Windows, Mac, or iOS, you need to clear the Office cache on your computer. Additionally, if you make changes to your add-in's manifest (for example, update file names of icons or text of add-in commands), you should clear the Office cache and then re-sideload the add-in using an updated manifest. Doing so allows Office to render the add-in as it's described by the updated manifest. See Clear the Office cache for more information.

huangapple
  • 本文由 发表于 2023年6月19日 22:12:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76507455.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定