为 Outlook 获取 Office.context.mailbox.item 中的所有可用值

Get all available values in Office.context.mailbox.item for Outlook

是否有 api 可以在 Office.js 中异步获取所有可用值,特别是在 Outlook 中 Office.context.mailbox.item

我在 docs 中没有看到任何内容。

我需要捕获 10 个左右的字段,并且迄今为止只实现了回调,例如

var ITEM = Office.context.mailbox.item;
var wrapper =  //fn to parse results and call next field getAsync as cb
ITEM.end.getAsync(wrapper);

您提供的参考文档指出 Office.context.mailbox.item 是命名空间。命名空间没有枚举命名空间中所有其他方法的方法和 return 一些合并结果,而是您将使用特定方法,获取结果并移动到您感兴趣的下一个方法。这是为 item.

提供的所有 Office.js API

如果您需要一次获取多个项目属性,您可以通过调用 Office.context.mailbox.makeEwsRequestAsync. Inside your XML request you may specify fields you are interested in and retrieve them with one request/response. Refer to Call web services from an Outlook add-in 文章查看 Office.js API 的 EWS 请求支持以获取更多信息。

另一种同时获取多个项目属性的方法是 Use the Outlook REST APIs from an Outlook add-in

我用 jQuery.when

解决了这个问题
const dStart = $.Deferred()
const dEnd = $.Deferred()

Office.context.mailbox.item.start.getAsync((res) => {
  // check for errors and fetch result
  dStart.resolve()
})

Office.context.mailbox.item.end.getAsync((res) => {
  // check for errors and fetch result
  dEnd.resolve()
})

$.when(dStart, dEnd).done(function() {
  // will fire when d1 and d2 are both resolved OR rejected
}

如果你不想 jQuery 你可以使用 promises 和 Promise.all