좋아요, 그래서 저는 Coffeescript와 Backbone에서 작동하도록 이벤트 바인딩을 얻는데 어려움을 겪고 있습니다. 나는 그것이 모든 것을 초기화하는 것과 관련이 있다는 느낌을 가지고있다. 이벤트 위임이 실행되지 않는 것 같은 기분이 듭니다.Coffeescript에서 백본 이벤트를 올바르게 바인딩 할 수없는 것 같습니다.
(function() {
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = Object.prototype.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
$(function() {
AppName.TitleView = (function(_super) {
__extends(TitleView, _super);
function TitleView() {
this.render = __bind(this.render, this);
this.initialize = __bind(this.initialize, this);
TitleView.__super__.constructor.apply(this, arguments);
}
TitleView.prototype.template = JST['templates/title'];
TitleView.prototype.collection = new AppName.Members;
TitleView.prototype.events = {
"keypress #search": "search",
};
TitleView.prototype.initialize = function() {
return $('#search').keypress(this.search);
};
TitleView.prototype.search = function() {
console.log('search handler call'););
});
};
TitleView.prototype.render = function() {
$('#app').html(this.template);
this.delegateEvents();
return this;
};
return TitleView;
})(Backbone.View);
});
}).call(this);
AppName.TitleView
이 (내 라우터에서 개막되는 차례로에 의해 쫓겨된다
$ ->
class AppName.TitleView extends Backbone.View
template: JST['templates/title']
collection: new AppName.Members
events:
"keypress #search" : "search",
initialize: =>
$('#search').keypress(@search) #doing it manually as a hack
search: ->
console.log('search handler call')
render: =>
$('#app').html(@template)
@delegateEvents() #this doesn't seem to do anything, nor does @delegateEvents(@events)
@
어떤이, 컴파일 할 때, 다음과 같은 : 여기
내보기 코드 기본app.coffee
) :
$ ->
class AppName.Router extends Backbone.Router
routes:
".*": "main"
main: ->
@titleView ||= new AppName.TitleView el: $('#app')[0]
@titleView.render()
나, 바인딩 백본 이벤트에서 #search
바인딩을 가져올 수 없습니다. 내 해킹 (코드에 있음)은 initialize
함수의 jQuery를 통해 바인딩하는 것입니다.
어떤 일이 벌어지고 있는지 알 수 있습니까? 나는 이것이 단순한 오타이거나 나쁜 초기화라고 생각하고있다.
당신의 선생님, 커피 스크립트 스택 오버플로 질문의 배트맨 있습니다! 고맙습니다! – CamelBlues