我将提交的表单作为数组“fsubs”存储在本地存储键中,如下所示:
var fsubs = JSON.parse(localStorage.getItem('fsubs') || "[]");
var fcodes = {"barcodeno" : this.form.value.barcode, "reelno" : this.form.value.reelno, "width" : this.form.value.width, "dia" : this.form.value.dia, "weight" : this.form.value.weight};
fsubs.push(fcodes);
localStorage.setItem('fsubs', JSON.stringify(fsubs));
现在的问题是我可能必须使用循环以表格形式打印这些值,但我不知道该怎么做。
条码 |雷尔诺
122121 | 232323
P.S.: 我想在 Angular 中使用 typescript 在我的组件中打印这个
最佳答案
像这样尝试:
组件.ts:
fsubList:Array<any> = JSON.parse(localStorage.getItem('fsubs'));
模板:
<table>
<tr>
<th>Barcode</th>
<th>Reelno</th>
</tr>
<tr *ngFor="let item of fsubList">
<td>{{item.barcodeno}}</td>
<td>{{item.reelno}}</td>
</tr>
</table>
关于javascript - 如何使用循环以表格形式打印 Localstorage 数组值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58214945/