0

私は現在バックボーン アプリを作成しており、非常に単純な問題と思われる問題に行き詰まっていますが、解決できないようです。

このようなビューがあるとしましょう(デモコード)

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 に渡したいと思います。これをモデルに保存するのが最善でしょうか、それとも変数をビューに渡すことができますか。

これに関するどんな助けも素晴らしいでしょう!

ありがとう

4

1 に答える 1

1

次のようなことができます。

initialize: function () {
     /** Initialize the variable when View is first created. */
     this.currentEvent = 'something'; 
},
buttonClicked: function (event) {
     /** Assign variable when button is clicked. */
     this.currentEvent = $(event.currentTarget);
},
linkClicked: function () {
     /** Receive the value of the variable and output it. */
     console.log(this.currentEvent);
}
于 2013-02-05T23:11:20.147 に答える