我想第一次實現Laravel分頁,我迷失在做什麼。Infinity Scroll Android和Laravel 5.2
我用下面從數據庫
$data = DB::table('news')->orderBy('created_at', 'asc')->paginate(15);
return $data;
提取數據,我得到了以下
{"total":3,"per_page":15,"current_page":1,"last_page":1,"next_page_url":null,"prev_page_url":null,"from":1,"to":3,"data":[{"id":1,"news_id":"3869577","news_title":"First Title","news_content":"First", "created_at":"2016-06-06 09:20:33","updated_at":"2016-06-06 09:20:33"},{"id":2,"news_id":"11081411","news_title":"Second Title","news_content":"Second.","created_at":"2016-06-07 07:20:33","updated_at":"2016-06-07 07:20:33"},{"id":3,"news_id":"14646385","news_title":"Third Title","news_content":"Third","created_at":"2016-06-07 14:58:33","updated_at":"2016-06-07 14:58:33"}]}
然後,我創建EndlessScrollListener
實現AbsListView.OnScrollListener
在我的片段,我那麼有:
listview.setOnScrollListener(new EndlessScrollListener() {
@Override
public boolean onLoadMore(int page, int totalItemsCount) {
// Triggered only when new data needs to be appended to the list
// Add whatever code is needed to append new items to your AdapterView
customLoadMoreDataFromApi(page);
// or customLoadMoreDataFromApi(totalItemsCount);
return true; // ONLY if more data is actually being loaded; false otherwise.
}
});
個
然後
// Append more data into the adapter
public void customLoadMoreDataFromApi(int offset) {
// This method probably sends out a network request and appends new data items to your adapter.
// Use the offset value and add it as a parameter to your API request to retrieve paginated data.
// Deserialize API response and then construct new objects to append to the adapter
}
問題
- 如何contruct下一個URL來獲取更多的數據?
- 我是否必須在Laravel的路線上捕獲新的網址?
感謝您的幫助
打電話給你的數據讀取內部customLoadMoreDataFromApi() – DKV
,我已經知道,有兩個問題,我問上面1和2 – BlackPearl
任務不需要構造URL - laravle這是否爲你 - 這是下一個頁面url屬性,如果沒有下一頁,則爲空,因爲您總共有3個元素,每頁15個。 2.只需調用這個URL,laravel就可以正確地獲取它。 –