In my view, i have a click event called clear to remove both model, and element from the page.. to use this in my view i have the function like this:
define(["backbone","../router/router"], function(Backbone,router){
"use strict"
var appView = Backbone.View.extend({
tagName:"li",
template:_.template($("#listTemp").html()),
events:{
"click" : "clear"
},
initialize:function(){
this.render();
},
render:function(){
this.$el.html(this.template(this.model.toJSON()));
return this;
},
listTrigger:function(){
var studentName = this.model.get("name");
router.navigate("#/list/" + studentName);
},
clear:function(){
this.model.clear(); // i am triggering models clear method here..
}
});
return appView;
})
in my model i have the method and clearing the modle and element..
define(["jquery","underscore","backbone"], function($,_,Backbone){
"use strict"
var appModel = Backbone.Model.extend({
initialize:function(){
console.log(this.view);
},
clear:function(){
this.destroy(); //it works..
this.view.remove(); // but it throw the error;
}
});
return appModel;
});
the error i am getting is:
Uncaught TypeError: Cannot call method 'remove' of undefined model.js:11
Backbone.Model.extend.clear model.js:11
Backbone.View.extend.clear appView.js:24
b.event.dispatch jquery.min.js:3
v.handle
why this 'undefined' - i am getting here.. how to solve it.. can any one help me..?