【发布时间】:2018-03-08 09:19:33
【问题描述】:
我正在编写一个嵌入式应用程序,我在其中使用 Office 365 库来访问通过全局对象 Office
向我的应用程序公开的 Outlook 电子邮件上下文我已经编写了 javascript 应用程序,其中我在 html 页面中包含了脚本 url,如下所示:
<script type="text/javascript" src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>
在我访问 ES6 javascript 函数中的上下文后,如下所示:
Office.initialize = function (reason) {
$(document).ready(function () {
Office.context.mailbox.addHandlerAsync(Office.EventType.ItemChanged, callbackfunction);
});
};
我想在 scala JS 中做同样的事情。
对于包含在 html 中的 Office js 库,如上所述。
在尝试访问 Office 对象后:
@js.native
@JSGlobal
object Office extends js.Any {
def initialize(f: String => Unit):js.Any = js.native
}
当我调用这个 Office 对象时,它会抛出错误。
def callback = (reason:String) => {
println(s"reason called in callback function => $reason")
}
Office.initialize(callback)
如何在 scala JS 中实例化和访问 office 对象?
错误:
VM3981 playground-fastopt-bundle.js:4078 Uncaught TypeError: $g.Office.initialize is not a function
at HTMLDocument.<anonymous> (VM3981 playground-fastopt-bundle.js:4078)
at mightThrow (VM4209 playground-fastopt-bundle.js:25770)
at process (VM4209 playground-fastopt-bundle.js:25838)
初始化在 Office 对象中不可用。我们必须在运行时加载函数。 错误信息:
在 Office.initialize 函数中添加您的初始化代码。
代码要点: https://gist.github.com/rajeevprasanna/8d4f193bc328f2c2d48e113960fb25a6
【问题讨论】:
-
到底抛出了什么错误?此外,您说您“想在 Scala.js 中做同样的事情”,但 Scala.js sn-p 据称 调用
initialize,而 JS sn-p 定义initialize。你想做的是哪一个?如果要调用它,它是在哪里定义的? -
我想调用初始化函数来初始化 office 上下文对象以访问 office 对象上可用的字段。