I am currently writing a Backbone app and have got stuck on what seems to be a very simple problem but cannot seem to work it out.
Let’s say I have a view like this (demo code)
var View = Backbone.View.extend({
initialize: function () {
console.log('created a view');
},
events: {
'click button':'buttonClicked',
'click link':'linkClicked'
},
buttonClicked: function (event) {
// I would like to store the event and pass this to the
// linkClicked function below when the linkClicked function is called
var $currentEvent = $(event.currentTarget);
},
linkClicked: function () {
// When the link is clicked I would like to gain access to $currentEvent
}
});
I would like to pass the variable $currentEvent to the function linkClicked when the link is clicked. Would it be best to store this in the model or can I pass the variable around the view.
Any help on this would be great!
Thanks
You can do something like this: