我目前正在编写一个 Backbone 应用程序,并且陷入了一个看似非常简单但似乎无法解决的问题。
假设我有这样的视图(演示代码)
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
}
});
单击链接时,我想将变量 $currentEvent 传递给函数 linkClicked 。最好将它存储在模型中,还是我可以在视图周围传递变量。
对此的任何帮助都会很棒!
谢谢