this is my server response for quetions and answers.. its a array.
[
{
"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,
},
]
the second item ( id 2 ) is response for question 1 because it have partent_id = 1 and id 3 is independent question
i want to show each responses under its own question in nested orded list if the question have any response.. how can i do that ?
i did somthing like this but it think it complatly wrong can anyone guide my to do that correctly ? thanks
my component for get questions and answers
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>