i've looked at pagination in backbone https://gist.github.com/838460, and it all seems very heavy handed for what I'm looking for.
I want to do an infinite scroll type paging, and I'm new to backbone, so maybe I'm just not understaning it correctly.
what I thought I would do is get the first collection, click a 'next' button, and get the results and just append that to the original collection and render the newly added items.
So I have this in my Router I have an index function
if(!myApp.list){ myApp.list = new myApp.collections.list; myApp.list.page = 1; } else { myApp.list.page++; } myApp.list.url='/recipes?page='+myApp.list.page; myApp.list.fetch({ add: true, success: function() { new myApp.views.list({ collection: myApp.list}); }, error: function() { new Error({ message: "Error loading documents." }); } });
which will create the collection if it does't exist, and if it does exist, increment the 'page' before requesting the next items in the list.
so the first part of my question is, is there anything wrong with this way of doing things?? Seems much simpler than the other solutions I've seen.
Question #2 seems ridiculous, but how do I then trigger the 'next' button to get the next list??
In my view, I have a 'next' button, but calling myApp.routers.list.index or myApp.views.list doesn't give me an updated list.
If you're using infinite scrolling on a long page, you're constantly loading more and more content into memory. This will have a negative impact on page performance, since the browser has much more work to do in order to render the page.
Infinite scrolling is a feature that allows you to load some pics on a website and then load more once the user reaches the end of the webpage (like we see on Pinterest). We will start off by creating three files, index. html , style. css , and app.
Infinite scroll is better suited for the exploration of content, where users are browsing aimlessly for something interesting. Infinite scroll is also very effective on mobile devices.
It's normal that myApp.routers.list.index()
doesn't work if there is the declaration of the Router, you need to call the instance of the router.
There are many things to say and I think the best explication is to see the code work and if It's that you want, learn the code.
I created an infinite listing with a "More" button to add models on the listing with using your code. The demo is on nodejitsu here : http://infinite-scroll.eu01.aws.af.cm/
You can show the complete code (client and server) on my gist on GitHub : https://gist.github.com/1522344 (I added a comment to explain how use the files)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With