Reputation: 2701
Am developing a hybrid app with backbone.marionette and phonegap. Am having issues with my collections not being ready in time for use in a view utilize them because they are still being fetched from the server. How can i preload my collections so my views can use them when the app starts?
Upvotes: 1
Views: 209
Reputation: 2249
If you are simply rendering them on screen using views. You can work with Marionette.CollectionView which will add the collection's models to the views as they are added.
var MyCollectionView = Marionette.CollectionView.extend({
//add Item View and other required fields
});
//myView will listen to the myCollection's events such as add, remove etc and will update itself
var myView = new MyCollectionView({collection: myCollection});
myCollection.fetch(); //Will fetch the data from the server
//Render the view whenever you wish.
myView.render();
If you really want to preload. You can first fetch and than render the view on success callback.
collection.fetch({
success : function(
view.render();
)
});
Upvotes: 1