javascript - 将 Office.onReady() 函数添加到 javascript
问题描述
我是 Javascript 新手,正在尝试让 Outlook Web 插件Office.onReady()
正确使用该功能。
https://docs.microsoft.com/en-us/office/dev/add-ins/develop/initialize-add-in
我尝试使用
Office.onReady()
.then
使我的函数与 office js API 一起工作,但随后我收到一个错误,即找不到我的函数。
代码:
$("#brief-summary").click(briefsummary);
$("#email-setup").click(emailsetup);
Office.onReady()
.then(function briefsummary() {
var msgFrom = Office.context.mailbox.item.from;
var msgfirstname = String(msgFrom.displayName).split(" ");
Office.context.mailbox.item.displayReplyAllFormAsync(
"Hello " +
msgfirstname[0] +
", <br> \
<br> Here is a brief summary on everything worked on: \
<br> \
<br>Thank you for your time, \
<br>"
);
});
结果:
Uncaught ReferenceError: briefsummary is not defined
所以我很确定我做错了。我还尝试Office.onReady();
在脚本开头使用。它抑制了Uncaught Error: Office.js has not fully loaded. Your app must call "Office.onReady()"
错误,但 office javascript 没有做任何事情。(假设会弹出一个新的回复窗口,里面有文字)
链接到托管应用程序的位置:https : //alloyautomateaddinbeta3.azurewebsites.net/index.html(虽然 office.js 仅在您在 Outlook 应用程序中时加载。但您可以sources
从 chrome 中的检查器转到并查看js 脚本)任何想法都会很棒。
解决方案
我似乎知道该怎么做,但我很笨拙。如果有人知道更好的清理方法,请告诉我。
我基本上是我的代码在这之间并且它起作用了:
Office.onReady((info) => {
if (info.host === Office.HostType.Outlook) {
#Insert code here
}
});
这很笨拙,因为它给了我一个警告说Function variables should not be placed in blocks. Use a function expression or move the statement to the top of the outer function
我将定期处理代码,因此我会随着时间的推移将我的答案更新为更好的答案,除非其他人也有答案。
谢谢
推荐阅读
- ruby-on-rails - 从 rails 中的 graphql api 返回 base64 字符串
- r - 如何通过反应性在闪亮中添加递归模块
- c# - 如何使用 Selenium C# 在 Chrome 中禁用下载警告?
- javascript - Nextjs 上的 ContentEditable,更新未显示在状态
- c++ - 类无法访问其自己的私有静态 constexpr 方法 - Clang 错误?
- jquery - jsTree:AJAX 调用后刷新内容然后打开所有
- sql-server - 在 Oracle SQL 中重写 SQL-Server 中的触发器
- angular7 - 组件中的角度反应式表单组清除错误未从模板中清除
- mysql - sql数据库中的条件
- ios - 是否可以使用 Xcode 使游戏控制器振动?