0

I have a view for a collection, and when I invoke its remove method I call its collection remove method as well, and I'm getting a 'ReferenceError: el is not defined' which doesn't make any sense to me, why would a collection need an el.

Invoking code:

try {

 myAppModel=backboneApp.views.privateViews.myAppsTabView.myAppsView.views.myAppsPrivateView.collection.get(appId);
                                            backboneApp.views.privateViews.myAppsTabView.myAppsView.views.myAppsPrivateView.remove(myAppModel);

} catch(e) {
console.log("delFromMyAppsCollection: Failed to delete app from collection e= " + e);
}

Remove method within View:

remove : function(modelToRemove) {
        alert('Killing!');
        console.log("MyAppsPrivateView.remove called with model: ", modelToRemove );   
        this.collection.remove(modelToRemove);
        console.log("MyAppsPrivateView.remove collection: ", this.collection );
        this._rendered = false;
    }

I guess it may be a better way to delete an element from a collection/view, but still it seems odd that the collection is complaining about not having an el, any ideas?

Thanks in advance.

Just in case,

view definition:

var MyAppsPrivateView = Backbone.View.extend( {
    // Reference to this collection's model.
    model:      PapsCatalog , // don't should be PapModel instead of a collection?
    templateId: Epc2G.myAppsTemplateId,
    template:   jQuery('#' + this.templateId).html(),

view instantiation:

var options = {
            className : "MyAppsContainer",
            uid : "myAppsPrivateView",
            collection : papsCollection,
            el : "#myAppsView"
        };

        var oMyAppsPrivateView = new MyAppsPrivateView(_.clone(options));
orlybg
  • 599
  • 1
  • 5
  • 15

1 Answers1

1

Might it relate to Backbone.View already having a remove method, and you’re overriding it?

This sounds like a composite view situation, have you considered having a view for every model in the collection?

Buck Doyle
  • 6,333
  • 1
  • 22
  • 35
  • Yes is pretty much like that, I have this view for a collection which in turn renders individuals views for each model in the collection. Don't know if my problem is caused because I override the remove method though. – orlybg May 10 '12 at 03:12