我正在开发一个带有ribs.marionette和phonegap的混合应用程序。
我的集合存在问题,无法及时准备好在视图中使用它们,因为它们仍是从服务器中获取的。
我如何预加载我的收藏集,以便我的视图在应用启动时可以使用它们?

最佳答案

如果您只是使用视图在屏幕上渲染它们。您可以使用Marionette.CollectionView,它将在添加视图时将集合的模型添加到视图中。

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();


如果您真的要预加载。您可以先获取并在成功回调中呈现视图。

collection.fetch({
   success : function(
      view.render();
   )
});

关于javascript - 如何从服务器预加载收集,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19258404/

10-09 23:51
查看更多