Javascript 如何在一个视图中获取多个集合
我试图在一个视图中获取多个集合。我有仪表板,那里有两张桌子。一个用于船舶,另一个用于船舶日。首先,我必须在仪表板上只取船的集合。已经完成了,现在我也要以同样的视角去拿shipday的收藏品,这在目前是非常具有挑战性的。我希望能得到你们的帮助。 这使得两个相互混淆的集合出现在视图中。提前谢谢Javascript 如何在一个视图中获取多个集合,javascript,backbone.js,underscore.js,Javascript,Backbone.js,Underscore.js,我试图在一个视图中获取多个集合。我有仪表板,那里有两张桌子。一个用于船舶,另一个用于船舶日。首先,我必须在仪表板上只取船的集合。已经完成了,现在我也要以同样的视角去拿shipday的收藏品,这在目前是非常具有挑战性的。我希望能得到你们的帮助。 这使得两个相互混淆的集合出现在视图中。提前谢谢 Parse.User.current().get('host').relation('ships').query().collection().fetch().then(collectionFetchSucc
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);
就像在评论区提到的Karan一样,您需要在第一个集合的fetch的回调函数中调用第二个集合的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。因为它需要两个集合,尽管它只有一个参数
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);
};
您需要从正在处理第一个集合的回调函数Success中调用第二个集合的get方法。@KaranPatyal请提供一些实际实现的解决方案。