You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Yeoman生成的Outlook Add-in无法正常执行按钮绑定函数求助

解决Outlook加载项按钮点击后持续显示加载提示的问题

问题根源

你的代码中,event.completed()在异步方法notificationMessages.replaceAsync()执行前就直接调用了。Office命令型加载项要求:必须在所有异步操作完成后调用event.completed(),否则会一直判定操作未结束,持续显示加载提示。

修复后的代码

修改commands.js,将event.completed()放到replaceAsync的回调函数中,确保异步操作完成后再标记事件结束:

Office.onReady(() => {
});

function action(event) {
  const message = {
    type: Office.MailboxEnums.ItemNotificationMessageType.InformationalMessage,
    message: "Performed action.",
    icon: "Icon.80x80",
    persistent: true,
  };

  // 显示通知消息,等待异步操作完成后标记事件结束
  Office.context.mailbox.item.notificationMessages.replaceAsync("action", message, function(asyncResult) {
    // 可选:通过asyncResult判断操作结果,方便调试
    if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
      console.log("通知已成功显示");
    } else {
      console.error("通知显示失败: " + asyncResult.error.message);
    }
    event.completed();
  });
}

Office.actions.associate("action", action);

补充说明

  • 所有Office.js中以Async结尾的异步方法,都需要等待其执行完成后,才能调用event.completed(),这是命令型加载项的核心规则。
  • 保留asyncResult的状态判断,能帮助你快速定位后续可能出现的其他问题。

内容的提问来源于stack exchange,提问作者ceid1987

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 17:02:06