我有一个将函数绑定到点击的事件。单击在同一视图中调用另一个函数。不幸的是,范围不是正确的范围。当我尝试执行 this.otherFunction() 时,分配给单击的函数与 this.otherFunction() 不在同一范围内。有没有办法在 otherFunction() 的范围内传递?
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());
},
这些都是同一个观点。
编辑:嗯,现在的问题是我收到了这个错误:未捕获的类型错误:对象 [object DOMWindow] 没有方法“renderLeaveGoal”。这似乎是我保存了错误的范围吗?