기능을 클릭에 바인딩하는 이벤트가 있습니다. 클릭하면 같은보기에서 다른 기능이 호출됩니다. 불행히도 범위가 올바른 범위가 아닙니다. this.otherFunction()을 수행하려고 시도 할 때 클릭에 할당 된 함수가 this.otherFunction()과 같은 범위에 있지 않습니다. otherFunction()의 범위를 전달하는 방법이 있습니까?백본을 사용하여 이벤트에 'this'를 전달하는 방법은 무엇입니까?
initialize: function() {
this.render();
if (joinedGoalList.get(this.model.id) != null) {
this.renderLeaveGoal();
} else {
this.renderJoinGoal();
}
},
events: {
"keypress #goal-update": "createOnEnter",
"click #join-goal": "joinGoal",
"click #leave-goal": "leaveGoal",
},
joinGoal: function() {
matches = joinedGoalList.where({id: this.model.get("id")});
if (matches.length == 0) {
joinedGoalList.create({goal_id: this.model.get("id")}, {wait: true, success: function() {
var self = this;
self.renderLeaveGoal();
}, error: function() {
console.log("error");
}});
}
},
renderLeaveGoal: function() {
console.log("render leave goal");
var template = _.template($("#leave-goal-template").html());
console.log(template);
$("#toggle-goal-join").html(template());
},
다음은 모두 동일한보기입니다. 잡히지 않은 TypeError : Object [object DOMWindow]에 'renderLeaveGoal'메서드가 없습니다. 이게 내가 잘못된 범위를 저장 한 것 같니?
코드를 추가 할 수 있습니까? – ataddeini