如何在一个视图中获取多个集合

How to fetch multiple collections in one view

我正在尝试在一个视图中获取多个集合。我有仪表板,那里有两张桌子。一个用于船舶,另一个用于船舶日。首先,我只需要在仪表板中获取船舶的集合。完成了,现在我还必须在同一个视图中获取 shipday 的集合,这在目前非常具有挑战性。我希望得到你们的帮助。 这使得两个集合相互混淆。提前致谢。

Parse.User.current().get('host').relation('ships').query().collection().fetch().then(collectionFetchSuccess, collectionFetchError);
Parse.User.current().get('host').relation('shipdays').query().collection().fetch().then(collectionFetchSuccess, collectionFetchError);

像评论中提到的Karanarea.You需要在第一个collection的fetch回调函数中调用第二个collection的fetch

Parse.User.current().get('host').relation('ships').query().collection().fetch({
  success : function(collection){
    shipFetchSuccess(collection)
    Parse.User.current().get('host').relation('shipdays').query().collection().fetch().then(shipdaysFetchSuccess, collectionFetchError)
  },
  error : function(){
    collectionFetchError()
  }
})

并且您还需要编辑 collectionFetchSuccess。因为它需要两个集合,尽管它只有 1 个参数。

  var shipdaysFetchSuccess = function(collection) {
      var shipdaysView = new ShipdaysTableView({ collection: collection });
      self.subViews.push(shipdaysView);
      self.$el.find('.shipdays').html(shipdaysView.render().el);
  };

  var shipFetchSuccess = function(collection) {

      var shipsView = new ShipsTableView({ collection: collection });
      self.subViews.push(shipsView);
      self.$el.find('.ships').html(shipsView.render().el);
  };