我有一个对象:
export class ObjectLayer {
id: number;
name: string;
}我从服务器中获取并将其设置为currentVersion
public currentVersion: ObjectLayer;
setVersion(object: ObjectLayer) {
this.currentVersion = object;
}然后用户可以更改currentVersion版本。如何随时将版本恢复到初始版本?
发布于 2021-06-19 03:04:19
保存初始状态。
private _oldVersion?: ObjectLayer;
public currentVersion: ObjectLayer;
setVersion(object: ObjectLayer) {
this._oldVersion = this.currentVersion;
this.currentVersion = object;
}
restoreVersion() {
if (!this._oldVersion) throw new Error('Nothing to restore');
this.currentVersion = this._oldVersion;
this._oldVersion = undefined;
}https://stackoverflow.com/questions/68040295
复制相似问题