我正在开发一个 Outlook 加载项,该加载项应该可以与 Outlook 网页版以及适用于 Windows 和 Mac 的 Outlook 365 配合使用。我遇到了 item.body.prependAsync 方法的问题。当我尝试调用此方法时,收到一条错误消息,指出 item.body.prependAsync 不是函数。
这是 console.log(item.body) 给我的:
{type: undefined, getAsync: ƒ}
getAsync: ƒ wt(e)
type: undefined
[[Prototype]]: Object
这是我构建 html 的方式:
<!DOCTYPE html>
<html>
<head>
<title>Addin test</title>
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>
<script>
let item;
Office.onReady((info) => {
if (info.host === Office.HostType.Outlook) {
item = Office.context.mailbox.item;
console.log(item.body);
item.body.prependAsync("text", function (asyncResult) {
if (asyncResult.status === Office.AsyncResultStatus.Failed) {
console.log("Action failed with error: " + asyncResult.error.message);
return;
}
console.log(`"${'text'}" prepended to the body.`);
});
}
});
</script>
</head>
</html>
我在日志中收到该错误:
Uncaught TypeError: item.body.prependAsync is not a function
at URLtoHTML/html?et=:14:19
at appsforoffice.microsoft.com/lib/1/hosted/office.js:76:23268
at t (appsforoffice.microsoft.com/lib/1/hosted/office.js:76:22669)
at appsforoffice.microsoft.com/lib/1/hosted/office.js:76:29316
at c (appsforoffice.microsoft.com/lib/1/hosted/office.js:76:4168)
at f.waitForFunction (appsforoffice.microsoft.com/lib/1/hosted/office.js:76:4257)
at e.j [as appReadyCallback] (appsforoffice.microsoft.com/lib/1/hosted/office.js:76:28650)
at appsforoffice.microsoft.com/lib/1/hosted/outlook-web-16.01.js:20:339988
这是我稍微缩小的manifest.xml:
<?xml version="1.0" encoding="UTF-8"?>
<OfficeApp
xmlns="http://schemas.microsoft.com/office/appforoffice/1.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0"
xmlns:mailappor="http://schemas.microsoft.com/office/mailappversionoverrides/1.0"
xsi:type="MailApp">
<Id>7218ed19-90f5-4ad6-99e8-8d17ee2556</Id>
<Version>1.0.0.0</Version>
<Hosts>
<Host Name="Mailbox" />
</Hosts>
<Requirements>
<Sets>
<Set Name="Mailbox" MinVersion="1.1" />
</Sets>
</Requirements>
<FormSettings>
<Form xsi:type="ItemRead">
<DesktopSettings>
<SourceLocation DefaultValue="URL to HTML" />
<RequestedHeight>250</RequestedHeight>
</DesktopSettings>
</Form>
</FormSettings>
<Permissions>ReadWriteItem</Permissions>
<Rule xsi:type="RuleCollection" Mode="Or">
<Rule xsi:type="ItemIs" ItemType="Message" FormType="Read" />
</Rule>
<DisableEntityHighlighting>false</DisableEntityHighlighting>
<VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides"
xsi:type="VersionOverridesV1_0">
<Requirements>
<bt:Sets DefaultMinVersion="1.1">
<bt:Set Name="Mailbox" />
</bt:Sets>
</Requirements>
<Hosts>
<Host xsi:type="MailHost">
<DesktopFormFactor>
<FunctionFile resid="Commands.Url" />
<ExtensionPoint xsi:type="MessageReadCommandSurface">
<OfficeTab id="TabDefault">
<Group id="msgReadGroup">
<Label resid="GroupLabel" />
<Control xsi:type="Button" id="msgReadOpenPaneButton">
<Label resid="TaskpaneButton.Label" />
<Supertip>
<Title resid="TaskpaneButton.Label" />
<Description resid="TaskpaneButton.Tooltip" />
</Supertip>
<Icon>
<bt:Image size="16" resid="Icon.16x16" />
<bt:Image size="32" resid="Icon.32x32" />
<bt:Image size="80" resid="Icon.80x80" />
</Icon>
</Control>
</Group>
</OfficeTab>
</ExtensionPoint>
</DesktopFormFactor>
</Host>
</Hosts>
<Resources>
<bt:Urls>
<bt:Url id="Commands.Url" DefaultValue="URL to HTML" />
</bt:Urls>
<bt:ShortStrings>
<bt:String id="GroupLabel" DefaultValue="Name" />
<bt:String id="TaskpaneButton.Label" DefaultValue="Action" />
</bt:ShortStrings>
</Resources>
</VersionOverrides>
</OfficeApp>
我正在 Outlook 网页版中测试此功能,网址为 https://outlook.office365.com/。知道为什么 item.body 可能不是预期的 Body 对象吗?任何帮助将不胜感激!
此 API 仅在撰写期间受支持,因此请尝试将此 API 与清单中的 MessageComposeCommandSurface 扩展点结合使用。