【发布时间】:2018-05-30 16:16:51
【问题描述】:
所以,我有点迷路了,我需要一些帮助。 我有一个来自服务器的 json,其中包含我不知道的数据。
基于此,我找到了一个在 SO 上显示 html 数据的解决方案: https://stackoverflow.com/a/50352965/9721446
但问题是每个“项目”都是数组中的一个条目,所以如果我 ngfor 数组,它将每一行作为一个项目输出,我希望该项目是每个结果的所有条目。
这里是 html:
<ng-container *ngFor="let item of singleArray | paginate: { itemsPerPage:411, currentPage: p} ">
<!-- All the entries -->
<div class="w3-container">
<!-- Table view-->
<table class="center">
<tr *ngIf="!item.tag.includes('URL') && !item.tag.includes('linkChal')">
<td><div class="col-xs-auto thick">{{item.tag.toLowerCase() | translate}}</div></td>
<td class="tab">{{item.value}}</td>
</tr>
<tr *ngIf="item.tag.includes('URL')">
<td>Link da entrada: </td>
<td> <a href="{{item.value}}">- Ver mais -</a></td>
</tr>
<tr *ngIf="item.tag.includes('linkChal')">
<td>Link do Challenge: </td>
<td> <a href="{{item.value}}">- Challenge -</a></td>
</tr>
</table>
<div style="background-color: #ff7d2a">
<ul *ngIf=" item.tag.includes('---------')"><p>New Entry</p></ul>
</div>
</div>
</ng-container>
Ts:
for(let i in res)
{
//array with entities from json
this.entity.push(i);
for(let j in res[i])
{
let val = Number(j)+1;
this.cont.push(i +" - nº: " + val );
this.singleArray.push({
tag: i,
value: val
});
for(let t in res[i][j])
{
this.test.push(t);
this.cont.push(t +" - "+ this.responseList[i][j][t]) ;
if(t.split(".",2)[1] === "CompositeId")
{
this.test.push("URL:");
//Get the id
this.cont.push(this.moduleName + "/" + t.split(".",2)[0] + "/" + this.responseList[i][j][t].match(/=(.*)_/)[1]);
//debugger;
this.singleArray.push({
tag: "URL:",
value: this.moduleName + "/" + t.split(".",2)[0] + "/" + this.responseList[i][j][t].match(/=(.*)_/)[1]
});
}
else if(t.split(".",2)[1] === "Challenge")
{
this.singleArray.push({
tag: "linkChal",
value: this.moduleName + "/" +t.split(".",2)[1] + "/" + this.responseList[i][j][t].match(/=(.*)_/)[1]
});
}
else {
this.singleArray.push({
tag: t,
value: this.responseList[i][j][t]
});
}
}
this.test.push("\n");
this.cont.push("\n");
this.singleArray.push({
tag: "---------\n",
value: "--------\n"
});
//it ends an item here
}
}
这是我的输出:
每一行都是数组中的一个条目,最大的问题是,如何将所有行/条目转换为“新条目”并将单个项目制作为 ngfor 并将数据显示到卡片中我已经有了..)
我试图创建一个数组并将 singleArray 推入其中(希望该新数组的每个条目都是我想要的项目),在 for(let j in res[i]) 的末尾 在 .ts 上,但它只是重复了所有条目,创建了一堆条目.. 在这里,在最后,我尝试用一些东西推送一个数组,然后 ngfor 它(它给了我想要的数字项目,但是我没有结果来访问它们..)
以前有人遇到过这个问题吗? 提前谢谢
编辑:这是 singleArray 的样子:
【问题讨论】:
标签: html angular typescript