I’m using backbone.js, and I’ve got a collection with does fetch() sometimes. I don’t want to pass the option {add: true} because of the way my subviews are created (the collection is looped over and each item is a new row appended to the current table). The one thing that I tried is just emptying the entire table and creating all new rows, but that is so slow since fetch() is run pretty often (when the scroll gets close to the end of the table). It begins to lag.
I’m hoping there’s an alternative where I can keep track of the new collection for appending purposes, yet have the whole collection as an entity. One possibility is creating a second collection and then adding it into the first, but I’m not sure how / if I should do that.
You could keep track of the current length of your collection, after new models are added to it use that as an offset to render the models from that point to the end of your collection.
UPDATE: just noticed this when I was looking through the underscore docs: http://documentcloud.github.com/underscore/#rest
To summarize it does this:
with this you just need to keep track of what your length was before additional items were added to the collection and then pass that into rest as the index.