我有一个集合的视图,当我调用它的remove方法时,我也调用它的集合remove方法,并且我得到了一个' ReferenceError:el未定义'这对我来说没有任何意义,为什么收藏需要一个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));
答案 0 :(得分:1)
它可能与已经拥有Backbone.View
方法的remove
有关,而你是否会覆盖它?
这听起来像复合视图情况,您是否考虑过对集合中的每个模型都有一个视图?