私は十分に単純なイベントオブジェクトを持つビューを持っています(それは甘いのでcoffeescriptで)
APP.bb.Recipe_Index = Backbone.View.extend
template: JST['templates/Recipe_Index']
el: $ "#recipes"
events:
'click a' : 'testFunction'
testFunction: () ->
console.log 'test called'
return 'this function'
私のイベントはバインドされていません。縮小されていない 0.5.3 Backbone.js ファイルの 967 行目に到達すると
delegateEvents : function(events) {
//snip
for (var key in events) {
var method = this[events[key]];
if (!method) throw new Error('Event "' + events[key] + '" does not exist');
var match = key.match(eventSplitter);
var eventName = match[1], selector = match[2];
method = _.bind(method, this);
eventName += '.delegateEvents' + this.cid;
if (selector === '') {
$(this.el).bind(eventName, method);
} else {
$(this.el).delegate(selector, eventName, method); <-- THIS ONE
}
}
},
Chrome にブレークポイントを設定すると、jQuery 構文が正しくなくなります。
selector == 'a'
eventName == click.delegateEventsview8'
method == 'function() {[native code]}'
セレクターは正しいのですが、なぜ 963 行目にイベント タイプを示す「クリック」文字列が追加されているのかわかりません。メソッドは、アンダースコアでバインドされる前に my method として読み取られるconsole.log
ので、正しいです。
最終結果は、私のイベントがトリガーされないということです。ここで何が間違っているのか疑問に思います。