I made posts feed with button which loads 10 more posts onClick. The problem is I don’t know when to hide that button if there are no posts left.
So I think I need to pass aditional variable in collection data (received from JSON), which tells to backbone there are more posts or not. How to receive this variable from the collection? Is it right thing to do?
Maybe there are better ways to do that without additional call to database?
If you absolutely need to avoid another service call, wrap your collection API response in a wrapper element which tells whether there are more posts.
GET /posts :
And use
Collection.parseto unwrap the data:So you can check it from the collection:
However if your data is volatile, i.e. it would be possible for new posts to be created while the user is on the page, this would mean that the user would not be able to load more posts, after they have once reached the end of it.