在JS / TS / Angular中-假设我们使用特定模式作为键来持久化数据对象-例如:“ DATA-A1”,“ DATA-A2”,“ DATA-B1”,...
是否可以使用通配符/正则表达式从StorageMap删除数据,例如:“ DATA-。*”?如果没有,最好的方法是... ???
constructor(private storage: StorageMap) {
....
}
... some function() {
// persist data to storage
// using a key of specific pattern:
this.storage.set('DATA-A1', dataObjectA1).subscribe(() => {});
this.storage.set('DATA-A2', dataObjectA2).subscribe(() => {});
this.storage.set('DATA-B1', dataObjectB1).subscribe(() => {});
... etc.
}
... other function() {
// delete all persisted data
// using a wildcard/regex
// -- HOW CAN WE BEST ACHIEVE THIS ???
this.storage.delete('DATA-.*').subscribe(() => {});
}