Possible Duplicate:
Call methods of different views in Backbone.js
I am new to backbone.js and I am using backbone.js with ASP.NET MVC 4.
I have a global class called SomeObject in which I have a deleteUser function. This function is binded with one of the click event of a button present in MyView2.
How do I call the following backbone.js different functions present in different views, from this global function/class.
- call myMethodB of MyView 2
- call myMethodA of MyView 1
- call myMethodC of AppView
Please guide me on this. I am still learning backbone.js and might be doing something wrong. Thanks
var SomeObject = function (Id, Name) {
var self = this;
this.Id = Id;
this.Name = Name;
this.deleteUser = function () {
console.log(self.Id, self.Name);
// call myMethodB of MyView 2
// call myMethodA of MyView 1
// call myMethodC of AppView
};
};
var MyModel = Backbone.Model.extends({
});
// View for a Main Grid
var MyView1 = Backbone.View.extend({
...
myMethodA: function(){
// do something with View 1
}
...
});
// View for subgrid in Main Grid
var MyView2 = Backbone.View.extend({
...
myMethodB: function(){
// do something with View 2
}
...
});
var AppView = Backbone.View.extend({
...
myMethodC: function(){
// do something with App View
}
...
});
You should use Backbone events – http://backbonejs.org/#Events
For example