【发布时间】:2018-08-08 01:10:09
【问题描述】:
我使用 Office javascript API 来构建 Outlook 加载项。我对保存约会然后关闭约会窗口的一些代码有疑问。我希望通过 API 保存约会后没有未保存的更改,但是在运行代码后我仍然得到“放弃更改”确认对话框。仅在编辑现有约会以及在保存之前向约会添加自定义属性时才会出现此问题。
这是我的(打字稿)代码的重要部分:
private saveAppointmentAndSetProperty(appointment: any): Observable<any> {
const subject = new Subject<any>();
Office.context.mailbox.item.loadCustomPropertiesAsync(
result => {
if (this.isErrorResult(result)) {
subject.error(result.error.message);
} else {
const properties = result.value;
properties.set('MY_PROPERTY', true);
this.saveCustomProperties(properties, subject,
() => this.saveAppointment(appointment, subject));
}
}
);
return subject;
}
private saveCustomProperties(properties: any, subject: Subject<any>, callback: () => void): void {
properties.saveAsync(result => {
if (this.isErrorResult(result)) {
subject.error(result.error.message);
} else {
callback();
}
});
}
private saveAppointment(appointment: any, subject: Subject<any>): void {
appointment.saveAsync((asyncResult) => {
if (this.isErrorResult(asyncResult)) {
subject.error(asyncResult.error.message);
} else {
appointment.close();
subject.next(asyncResult.value);
subject.complete();
}
});
}
saveAppointmentAndSetProperty() 是代码的入口。如果我改为在 saveAppointment 中执行代码,我看不到任何问题。
【问题讨论】:
标签: api typescript outlook-addin office-js