【发布时间】:2019-10-02 11:51:00
【问题描述】:
我正在尝试从本地存储中清除对象 (collectionFilter) 中的字段,使用 localStorage.removeItem('collectionFilter') 除日期字段外,其他字段已被删除,(请注意,我是 javascript 和 angular 新手)
我试过了,但它不适合我
Trying to remove particular value from local storage key
下面是代码
localStorage.removeItem('collectionFilter');
localStorage.setItem('collectionFilter', JSON.stringify(data));
this.collectionService.searchCollection(filter, event.itemsPerPage, offset)
.subscribe((payload) => {
if (this.page !== event.page) {
return;
}
this.queryResult = payload.queryResult;
this.totalAmount = payload.sum;
this.working = false;
});
本地存储数据
agency: ""
endDate: "2019-10-03"
invoiceAccountCode: ""
paymentChannel: ""
paymentProviderReference: ""
prr: ""
receiptNumber: ""
revenueItem: ""
revenueSource: "6"
startDate: "2019-01-01"
tin: ""
预期结果
agency: ""
endDate: ""
invoiceAccountCode: ""
paymentChannel: ""
paymentProviderReference: ""
prr: ""
receiptNumber: ""
revenueItem: ""
revenueSource: ""
startDate: ""
tin: ""
【问题讨论】:
-
您可以添加存储在
localStorage中的示例数据吗? -
删除密钥后您想要的预期数据是什么。您的方法是正确的。您遇到了什么错误
-
@ShivShankarNamdev 我已经添加了预期的数据
-
如果要清除“所有”属性,最简单的方法是将collectionFilter 设置为所有属性为空。
标签: javascript angular date