【问题标题】:Adding ion-item to previous ion-item instead of replacing it将 ion-item 添加到先前的 ion-item 而不是替换它
【发布时间】:2018-05-08 17:14:43
【问题描述】:

我从带有分页的 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>

现在发生的事情是它获取第二页并将其替换为第一页,我需要将其添加到第一个 ion-item 下方

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)); }

【问题讨论】:

    标签: angular typescript ionic-framework


    【解决方案1】:

    只需将您的新问题推送到现有数组中,而不是像这样分配新数据 -

     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)); 
    }
    

    【讨论】:

    • 它说{}类型不存在属性长度
    • 现在它说 {} 类型上不存在属性数据
    • 试试用控制台调试吧,现在很简单的问题
    猜你喜欢
    • 2017-04-08
    • 2021-08-05
    • 2019-08-01
    • 2020-03-25
    • 2018-09-25
    • 1970-01-01
    • 2020-11-18
    • 2018-11-02
    • 2018-12-25
    相关资源
    最近更新 更多