假设我在javascript中有这样的对象:
obj = {
prop1 : 0,
prop2 : 1,
func1 : function (){
var x = {
func_Inner : function(){
//ATTEMPTING TO CALL FUNC2 ON obj WON'T WORK
this.func2()
//NEITHER THIS
this.func2().bind(obj);
}
}
x.f()
this.func2()
},
func2 : function (){
console.log(this)
console.log(this.prop1,this.prop2)
}
}
我想从func_Inner中调用func2,我怎么能这样做?
答案 0 :(得分:2)
问题是函数class VisitCreateForm(ModelForm):
class Meta:
model = models.Visit
...
# Allow only one visit per day
def clean_visit_date(self):
visit_date = self.cleaned_data['visit_date']
if models.Visit.get_visits(visit_date, visit_date, self.kwargs['orgStr']):
raise ValidationError('There is already a visit on this date')
的上下文,它不是obj的上下文。
另一种方法是将上下文func_Inner
绑定到函数this
func_Inner