事件处理程序 ItemSend 再次调用 Office.onReady

发布于 2025-01-14 15:48:25 字数 1154 浏览 4 评论 0原文

我已经在清单中定义了一个事件

<ExtensionPoint xsi:type="Events">
  <Event Type="ItemSend" FunctionExecution="synchronous" FunctionName="itemSendHandler" />
</ExtensionPoint>

,而我的 main.js 中有类似

window.test1 = 5
Office.onReady((info) => {
  if (info.host === Office.HostType.Outlook && !sendEvent) {
    // $() is equivalent to $(document).ready() which is deprecated
    $(function () {
      window.test1 = 20
      $('#test_button').on('click', () => { window.test1 = 10 })
      
      // do more stuff
    })
  }
})

function itemSendHandler (event) {
  sendEvent = event
  //...
}

加载插件并检查 window.test1 的内容,并且如预期的那样为 20。我单击 #test_button,再次检查,现在 window.test1 按预期为 10。但是,当我单击 Outlook 中的“发送”按钮并将 window.test1 转储到 Office.context.mailbox.item.notificationMessages 时,现在 window.test1 是又是20。

为什么当我单击“发送”按钮时会再次调用 Office.onReady 如何检测 ItemSend 事件处理程序正在调用 Office.onReady

I hade defined an event in my manifest

<ExtensionPoint xsi:type="Events">
  <Event Type="ItemSend" FunctionExecution="synchronous" FunctionName="itemSendHandler" />
</ExtensionPoint>

And my main.js has something like

window.test1 = 5
Office.onReady((info) => {
  if (info.host === Office.HostType.Outlook && !sendEvent) {
    // $() is equivalent to $(document).ready() which is deprecated
    $(function () {
      window.test1 = 20
      $('#test_button').on('click', () => { window.test1 = 10 })
      
      // do more stuff
    })
  }
})

function itemSendHandler (event) {
  sendEvent = event
  //...
}

I load the Addin and check for window.test1 and is 20 as expected. I click #test_button, check again and now window.test1 is 10 as expected. But when I click the button Send in Outlook and dump window.test1 into Office.context.mailbox.item.notificationMessages now window.test1 is 20 again.

Why is Office.onReady being called again when I click the Send button?
How can I detect that Office.onReady is being called by ItemSend event handler?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半夏半凉 2025-01-21 15:48:25

当您说“我加载插件”时,这是否意味着在任务窗格/执行函数中?

如果是这样,则 ItemSend 功能不会使用与任务窗格相同的沙箱/实例。 (事实上​​,所有按钮/扩展点都不会重用任何 Web 实例)。换句话说,如果一个按钮上有一个任务窗格,另一个按钮上有一个 ExecuteFunction,以及 ItemSend 处理程序。然后它们被视为单独的实例,并且都会触发自己的 onReady。

如果您需要将信息从一个实例传递到另一个实例,建议使用 CustomProperties 将信息保存到项目中,然后可以从其他加载项实例中引用。
https://learn. microsoft.com/en-us/javascript/api/outlook/office.customproperties?view=outlook-js-preview

即在您的任务窗格中,您可以保存自定义属性 test1 = 20。然后在您的itemSend 处理程序加载自定义属性以获取 test1 的值。

When you say "I load the Addin" does this mean in a Taskpane/ExecuteFunction?

If so, the ItemSend feature does not use the same sandbox/instance as the Taskpane. (In fact all buttons / extensions points do not reuse any web instances). In other words, if you have a Taskpane on one Button, and an ExecuteFunction on another Button, and ItemSend handler. Then they are treated as separate instance, and will all trigger their own onReady.

If you need to communicate information from one instance to another, it is recommended to use the CustomProperties to save information to the item, and then it can be referenced from other add-in instances.
https://learn.microsoft.com/en-us/javascript/api/outlook/office.customproperties?view=outlook-js-preview

i.e In your taskpane you could save a custom property test1 = 20. Then in your itemSend handler load custom property to get the value of test1.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文