Backbone JS Pagination

前端 未结 1 1747
无人共我
无人共我 2021-01-31 23:50

I have been trying out backbone JS with rails and really like the way it organises the frontend. I have implemented a pagination solution similar to the one here https://gist.gi

相关标签:
1条回答
  • 2021-02-01 00:26

    If your objective is to query & display items when a page is requested, you could do something like (pseudocode):

    pages = {}
    
    
    // when page N is needed
    function fetch_page(n) {
     if (!pages[n]) {
        pages[n] = new ItemsCollection({page: n})
        pages[n].fetch();
     }     
    }
    

    So you keep a collection for each page.

    If you also need a collection of all the items fetched so far, just keep one - and add fetched items to it every time you get them from the server.

    0 讨论(0)
提交回复
热议问题