【发布时间】:2017-11-07 20:07:12
【问题描述】:
我的数据被存储在一个字符串中
我使用 JSON.parse 将数据转换为数组
this.items = JSON.parse(todos);
我有一个打印出我的数组的结果页面: 阵列1 数组2 数组3
我在每个数组后面都有一个删除按钮,它从列表中删除项目,但不是从本地存储中删除。我做错了吗?
list.html
<ion-item-sliding *ngFor="let item of items">
<ion-item>
<p>{{item.amount}}tk X {{item.class}} / {{item.size}}ml / {{item.proof}}%</p>
</ion-item>
<ion-item-options>
<button danger (click)="removePost(item)">
<ion-icon name="trash"></ion-icon>Remove
</button>
</ion-item-options>
</ion-item-sliding>
list.ts
removePost(item){
let index = this.items.indexOf(item);
if(index > -1){
this.items.splice(index, 1); // works
this.storage.remove(this.items[index]); // doesn't work
}
}
【问题讨论】:
-
您如何将数据存储在本地存储中?本地存储不带数组或对象,只带字符串。
-
this.items = JSON.parse(todos);
-
this.items[index] 这是一个对象吧?
-
你可以分享存储项目的截图吗?
标签: arrays angular typescript ionic2 storage