【问题标题】:Integrate the pull to refresh feature in Ionic 3 with Wordpress将 Ionic 3 中的下拉刷新功能与 Wordpress 集成
【发布时间】:2018-11-01 10:10:38
【问题描述】:

我正在开发一个使用 REST API v2 与 Wordpress 集成的 Ionic3 应用程序,我需要包含 pull to refresh 功能,但我不明白如何使用我的代码来实现。

这是检索我的帖子的函数

getPostsWordpress(){
    if(!(this.posts.length > 0)){
      let loading = this.loadingCtrl.create();
      loading.present();
      this.wordpressService.getRecentPostsWithSort(this.categoryId,this.sort) 
      .subscribe(data => {
        for(let post of data){
          post.excerpt.rendered = post.excerpt.rendered.split('<a')[0] + "</p>";
          this.posts.push(post);
        }
        loading.dismiss();
      });
    }
  }

...

doInfinite(infiniteScroll) {
    let page = (Math.ceil(this.posts.length/10)) + 1;
    console.log("PAGE_"+page)
    console.log("this.posts.length_"+this.posts.length)
    let loading = true;

    this.wordpressService.getRecentPostsWithSort(this.categoryId,this.sort, page)
    .subscribe(data => {
      for(let post of data){
        if(!loading){
          infiniteScroll.complete();

        }
        post.excerpt.rendered = post.excerpt.rendered.split('<a')[0] + "</p>";
        this.posts.push(post);
        loading = false;
      }
    }, err => {
      this.morePagesAvailable = false; 
    }) 
  }  

doInfinite 让我实现无限滚动,一切正常!

如何从 ionic 文档中集成 pull 以刷新? 这是文档中的示例,我不明白如何在我的项目中使用它。

doRefresh(refresher) {
    console.log('Begin async operation', refresher);

    setTimeout(() => {
      console.log('Async operation has ended');
      refresher.complete();
    }, 2000);
  }

有人可以帮助我吗? 提前谢谢!

【问题讨论】:

    标签: wordpress ionic-framework pull-to-refresh


    【解决方案1】:

    将此添加到您的 html

    <ion-refresher (ionRefresh)="doRefresh($event)">
    <ion-refresher-content
        pullingIcon="arrow-dropdown"
        pullingText="Pull to refresh"
        refreshingSpinner="circles"
        refreshingText="Refreshing...">
    </ion-refresher-content>
    

    然后在你的刷新

    doRefresh(refresher) {
    console.log('Begin async operation', refresher);
    //ur function e.g getPostWordPress()
    setTimeout(() => {
      console.log('Async operation has ended');
      refresher.complete();
    }, 2000);}
    

    【讨论】:

    • 对不起,我不明白你的答案,这只是文档中的代码......问题是我无法将它与我的代码集成以使其工作。跨度>
    • 你可以拉刷新但列表不刷新?
    猜你喜欢
    • 2018-07-17
    • 1970-01-01
    • 2020-03-26
    • 2019-12-29
    • 1970-01-01
    • 2015-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多