Last active
August 29, 2015 14:14
-
-
Save jessekinsman/6cc3ba1eb3667991299f to your computer and use it in GitHub Desktop.
Backbone add models to collection (Titanium Alloy or any Backbone Collection)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Often you want to dump a large amount of models into a collection at one time. | |
// This take models from one collection and adds thems to another | |
// This assumes you have two collections already initialized with models. | |
// If you had one collection that had change events wired to render a view you might use this. | |
collectionAttachedToView.add(collectionToAdd.models); | |
//This would work, however, it will fire an add event everytime one of the models is added. | |
// This will slow your app down ad it will try to render over and over again as many times as the models you are adding | |
// To avoid this, use the silent option | |
collectionAttachedToView.add(collectionToAdd.models, {silent: true}); | |
//Then fire an add event once so that it rerenders only once | |
collectionAttachedToView.trigger("add"); | |
// This is very helpful in pagination. I was creating an Alloy app for the Iphone in Titanium and I was getting results from a database | |
// I wanted to create the models before I added them to the collection that was attached to the listView | |
// It was so slow as it was rerending the listview everytime a model was added. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment