angular - 将 ion-item 添加到先前的 ion-item 而不是替换它
问题描述
我从带有分页的 api 获取问题列表,我有一个按钮,它运行一个函数并获取下一页问题。我需要添加这个之前的 ion-item 而不是替换它,这是我的代码:
home.html:
<div *ngFor="let question of this.questions?.data">
<ion-item class="questions_div" (click)="goToConsult(question.id);">
<p text-wrap>{{question.title}}</p>
<span>{{question.created_at | jalali}}</span>
</ion-item>
</div>
现在发生的是它得到第二页并用第一页替换它,我需要将它添加到第一个离子项下面
home.ts=>
loadMore(currentPage){
this.nextPage = ++this.currentPage;
this.showLatestQuestions(this.nextPage);}
showLatestQuestions(currentPage){
this.questionsProvider.getLatestQuestions(currentPage)
.then(data => {
this.questions = data;
this.currentPage = this.questions.current_page;
return this.currentPage;
})
.catch(error => alert(error)); }
解决方案
只需将您的新问题推送到现有数组中,而不是像这样分配新数据 -
showLatestQuestions(currentPage){
this.questionsProvider.getLatestQuestions(currentPage)
.then(data => {
for(let i=0; i< data.data.length;i++){
this.questions.push(data.data[i]);
}
this.currentPage = this.questions.current_page;
return this.currentPage;
})
.catch(error => alert(error));
}
推荐阅读
- java - 将 ArrayList 中的信息从一个类传递到 WindowsBuilder GUI 类
- html - 在 WordPress 中,如何设置文本限制或在达到一定长度时打破文本
- c# - 无法将数据保存在 SQL Server 数据库中,该文件放在哪里?
- r - R ggplot2,在图的底部(外部)显示主题的数量
- html - 容器有什么问题
- php - 仅当新数据不存在时才插入新数据
- java - java android getResources().getIdentifier() of elment at alertdialog with LayoutInflater
- vb.net - 我如何能够在 VB.net 中循环我的随机数生成器
- spring-boot - 接收远程服务对发布者的 http 响应
- python - 使用 Python MoviePY 连接视频太慢