【发布时间】:2018-11-12 06:42:49
【问题描述】:
这是我对问题和答案的服务器响应。它是一个数组。
[
{
"id": 1,
"product": 1,
"user": "alex",
"text": "is it ok?",
"parent_id": null,
},
{
"id": 2,
"product": 1,
"user": "john doe",
"text": "yes its ok.",
"publish": true,
"parent_id": 1,
},
{
"id": 3,
"product": 1,
"user": "shiva",
"text": "how can i .. . .",
"publish": true,
"parent_id": null,
},
]
第二项 (id 2) 是对问题 1 的响应,因为它的 partent_id = 1 并且 id 3 是独立问题
我想在嵌套的有序列表中显示每个答案在其自己的问题下 如果问题有任何回应..我该怎么做?
我做了这样的事情,但它认为这是完全错误的,谁能指导我正确地做到这一点?谢谢
我的获取问题和答案的组件
this._store.viewSingleProductQA(this.product.product_id).subscribe(data => {
this.questions = data;
this.responses = this.questions.filter(d => d.parent_id == this.questions.id)
});
html:
<div>{{question?.user}}</div>
<div>{{question.text}}</div>
</div>
<div *ngFor="let res of responses">
{{res.text}}
</div>
【问题讨论】:
标签: angular typescript angular5