![](/img/trans.png)
[英]Office JavaScript API for Outlook - how can I refresh my web add-in when location changes?
[英]How do I watch for changes to the To/CC fields for emails in Outlook Add-In's Javascript API?
在旧版Office API的文档中,我看到当用户撰写电子邮件时,可以监视TO / CC字段的更改。 这在他们用于Office 365的新Javascript API中公开了吗? 无论哪种方式,我似乎都找不到明确的答案。
这可能不是您想要的答案,因为我找不到您所描述的对观察者的任何引用,但这是我的“模糊但有效”的解决方案。
在您的加载项中,声明一个名为toRecipients
的全局(到应用程序)变量。 接下来,在Office.initalize
函数中添加以下代码,以初始化toRecipients
变量,然后启动循环以检查更改。
var item = Office.context.mailbox.item;
if (item.itemType === Office.MailboxEnums.ItemType.Message) {
item.to.getAsync(function(result) {
toRecipients = result.value;
});
}
setInterval(function(){ isToRecipientsChanged(); }, 1000);
这是检查更改的代码。 我使用了equals
函数来检查“收件人”收件人是否已更改。
function isToRecipientsChanged() {
var item = Office.context.mailbox.item;
item.to.getAsync(function(result) {
if (!toRecipients.equals(result.value)) {
toRecipients = result.value;
}
});
}
最后,这是我使用的equals
方法。 我是从另一个StackOverflow问题中得到的 。 注意,我更改了检查以检查电子邮件地址而不是对象实例。
Array.prototype.equals = function (array) {
// if the other array is a falsy value, return
if (!array)
return false;
// compare lengths - can save a lot of time
if (this.length != array.length) {
return false;
}
for (var i = 0, l=this.length; i < l; i++) {
// Check if we have nested arrays
if (this[i] instanceof Array && array[i] instanceof Array) {
// recurse into the nested arrays
if (!this[i].equals(array[i]))
return false;
}
else if (this[i].address != array[i].address) {
// Warning - two different object instances will never be equal: {x:20} != {x:20}
return false;
}
}
return true;
}
因此,这是我的“模糊但有效”的解决方案。 但是,如果您向我提供问题中引用的较旧的文档,我会四处询问是否新的API可以使您更有效(更优雅)地完成此任务。
抱歉,您无法“实时”检测到。 邮箱API几乎没有可以挂接到的事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.