如果这是一个愚蠢的问题,我很抱歉。
我正在尝试一些创建office插件的东西。
我想要它做的是获取您正在撰写的会议的开始时间,并将其放入HTML div中。这是我的.js:
Office.onReady().then(function() {
var item = Office.context.mailbox.item;
getStartTime();
});
function getStartTime() {
var timeText = document.getElementById("time");
timeText.innerHTML = item.start.getAsync();
}如果我将"item.start.getAsync()“改为字符串,一切都会正常工作。
如果我把它改成"item.start“,那么div就变成了"undefined”
有谁能给我指个方向吗?我有没有试着用正确的方式来做这件事?
谢谢
发布于 2018-11-28 00:29:44
正如@PatrickHund在注释中提到的,getAsync具有异步性质,您需要在回调上处理函数的结果。完整的例子说明了如何通过链接使用Get or set the time when composing an appointment in Outlook。你的代码可能看起来像...
function getStartTime() {
item.start.getAsync(
function (asyncResult) {
if (asyncResult.status == Office.AsyncResultStatus.Failed){
write(asyncResult.error.message);
}
else {
// Successfully got the start time, display it, first in UTC and
// then convert the Date object to local time and display that.
write ('The start time in UTC is: ' + asyncResult.value.toString());
write ('The start time in local time is: ' + asyncResult.value.toLocaleString());
}
});
}
// Write to a div with id='message' on the page.
function write(message){
document.getElementById('time').innerText += message;
}https://stackoverflow.com/questions/53503378
复制相似问题