rotundasoftware / backbone.collectionView

Easily render backbone.js collections. In addition to managing model views, this class supports automatic selection of models in response to clicks, reordering models via drag and drop, and more.
http://rotundasoftware.github.io/backbone.collectionView/
Other
171 stars 27 forks source link

Multiple views rendered for the same model #77

Open edwh opened 7 years ago

edwh commented 7 years ago

I haven't managed to get a clear reproduction of this case yet, but I have a collection view where one of the models in the collection results in multiple views.

Has anyone else seen this? I've got a speculative fix, to check if the model already exists.

       _registerCollectionEvents : function() {
            this.listenTo( this.collection, "add", function( model ) {
                var modelView;

                if( this._hasBeenRendered ) {
                    **modelView = this.viewManager.findByModelCid( model.cid );

                    if (!modelView) {**
                        modelView = this._createNewModelView( model, this._getModelViewOptions( model ) );
                        this._insertAndRenderModelView( modelView, this._getContainerEl(), this.collection.indexOf( model ) );
                    **}**
                }

                if( this._isBackboneCourierAvailable() )
                    this.spawn( "add", modelView );
                else this.trigger( "add", modelView );
            } );
edwh commented 7 years ago

Well, that fix didn't work. Anyone else seen this?