我想第一次实现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就可以正确地获取它。 –