Why do you create a CollectionB instance that retrieves in the ModelViewA rendering method?
var collectionB = new CollectionB(); var collectionViewB = new CollectionViewB(); collectionB.fetch({ self.$el.append(collectionViewB.render().el); });
It does not even analyze. Are you sure you did not accidentally edit the anonymous success function? First, let me assume that not exactly what your code shows. That is, it should be something like:
collectionB.fetch({ success: function(){ self.$el.append(collectionViewB.render().el); } });
?
Let go of it.
Therefore, when ModelViewA displayed, it is obvious that CollectionB is going to retrieve something, and then collectionViewB will be displayed, because that is what you told it to. Now can you do ModelViewA s?
CollectionViewA = Backbone.View.extend({ initialize : function() { this.collection.on('add', this.renderOne, this); }, ...
renderOne : function(model) { console.log('Added to Collection A'); var view = new ViewA({ model : model }); this.$el.append(view.render().el); return this; }
What is this ViewA ? Could this also apply to ModelViewA ?
If so, we can guess what happens:
Your CollectionViewA instance displays a ModelViewA instance for each addition. Each instance rendering of a ModelViewA creates an instance of CollectionB instance ( CollectionB ) and collectionViewB ( collectionViewB ), and fetching CollectionB has a successful method that displays collectionViewB . If CollectionB has any models, for each model it is successfully registered on the βAdded to Collection Bβ console before attempting to visualize instances of ViewB that, if I understand you correctly, fail (which is probably why you only have one ", Added Post Collection B ".
Now about why console logs are in the reverse order ... I'm still trying to figure it out. Maybe I missed something.
In any case ... This situation is not perfect. I'm not sure what I could say to improve your code. Calling fetch from render seems to me like you are specifying a lot of what needs to be done in the rendering code. I'm not even sure that you knew that fetch should have started.