Angular / TS使用通配符/正则表达式从StorageMap @ ngx-pwa / local-storage删除一组持久数据

时间:2019-11-05 17:40:04

标签: javascript angular typescript local-storage

在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(() => {});

}

0 个答案:

没有答案