1

私はhttps://developer.yummly.com/documentationからデータを引き出す私のアプリに無限のスクロールをかけようとしています。最大結果の値は現在50に設定されています。私はそれがあなたがスクロールポイントになるたびに同じ量で増加したいです。イオン2:無限スクロールが動作しない

私のAPI呼び出しが

perpage: number = 50; 

loadCategory(category:any, start:number=0) { 
    var url = "http://api.yummly.com/v1/api/recipes?_app_id=...&_app_key=..."; 

    if (categoryCache[category.categoryId]) { 
     // already loaded data 
     return Promise.resolve(categoryCache[category.categoryId]); 
    } 

    // don't have the data yet 
    return new Promise(resolve => { 
     // We're using Angular HTTP provider to request the data, 
     // then on the response, it'll map the JSON data to a parsed JS object. 
     // Next, we process the data and resolve the promise with the new data. 
     var params = ""; 

     category.apiParams.forEach(paramPair => { 
     params += "&" + paramPair.key + '=' + paramPair.value; 
     }); 

     this.http.get(url + params + "&maxResult=" + this.perpage + "&start=" + start) 
     .map(res => res.json()) 
     .subscribe(data => { 
      // we've got back the raw data, now generate the core schedule data 
      // and save the data for later reference 
      console.log(data); 
      console.log(this.http.get); 
      categoryCache[category.categoryId] = data.matches; 
      resolve(categoryCache[category.categoryId]); 
     }); 
    }); 
} 

ここから始まると誰もがそれは素晴らしいだろう手助けができれば、その後の私のページ.TSファイルは

public api: any = []; 
    private start:number=50; 

    loadRecipes(){ 
    return new Promise(resolve => { 
     this.apiAuthentication.loadCategory(this.navParams.data) 
     .then(data => { 
     this.api = data; 
     }); 
    }) 
    } 


    doInfinite(infiniteScroll:any) { 

    setTimeout(() => { 
     // Text goes here 
     this.start = 100; 
     infiniteScroll.complete(); 
    }, 500); 
    } 

です。

答えて

0

loadRecipiesdoinfinite()に電話する必要があります。すべてのエラーをクリアして、コンソールに入れてから、それはより多くの50に追加されますログインすると思われる

doInfinite
api:any[]=[];//initialize to empty array 
loadRecipes(scroll?:any,start?:any){ 
    return new Promise(resolve => { 
     this.apiAuthentication.loadCategory(this.navParams.data,start) 
     .then(data => { 
     this.api.push(data); 
     if(scroll){ 
      scroll.complete() 
     } 
     },err=>{ 
     if(scroll){ 
      scroll.complete() 
     } 
     }); 
    }) 
    } 

doInfinite(infiniteScroll:any) { 
    this.loadRecipies(infiniteScroll,this.start); 
    this.start+=50; 
    } 
+0

こんにちは:あなたのpagenation、に変更loadRecipiesについては
。しかしフロントエンドでは実際には何もロードされませんか? – BA1995

+0

あなたは何か特別な理由で 'loadRecipies'に新しい約束をしていますか? –

+0

また、 'this.api'をプッシュする必要があります。リセットしないでください –

関連する問題