0

我有一个集合的视图,当我调用它的 remove 方法时,我也调用它的集合 remove 方法,我得到一个 'ReferenceError: el is not defined' 这对我来说没有任何意义,为什么会一个集合需要一个 el。

调用代码:

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 : 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;
    }

我想这可能是从集合/视图中删除元素的更好方法,但是集合抱怨没有 el 似乎仍然很奇怪,有什么想法吗?

提前致谢。

以防万一,

视图定义:

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(),

查看实例化:

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

        var oMyAppsPrivateView = new MyAppsPrivateView(_.clone(options));
4

1 回答 1

1

可能与Backbone.View已有remove方法有关,而您正在覆盖它?

这听起来像是一种复合视图的情况,您是否考虑过为集合中的每个模型创建一个视图?

于 2012-05-09T23:36:08.023 回答