[英]Backbone.js: call a method from another method within a view?
I am working in Backbone. 我在Backbone工作。 Working within a View, I would like to call a method from within another method.
在View中工作,我想从另一个方法中调用一个方法。
events: {
"click span": "updateURL",
"click .tag": "clearTag"
},
updateURL: function() {
// do stuff
},
clearTag: function(e) {
console.log(this);
// this fails
this.updateURL();
},
But this
in clearTag
appears to be bound to an element, and updateURL
is not being called. 但是
clearTag
中的this
似乎绑定了一个元素,并且没有调用updateURL
。 Is there a way I can call updateURL
from within clearTag
? 有没有办法可以在
clearTag
调用updateURL
?
From the Backbone source regarding view event bindings: 从关于视图事件绑定的Backbone源:
// Callbacks will be bound to the view, with `this` set properly.
// Uses event delegation for efficiency.
// Omitting the selector binds the event to `this.el`.
// This only works for delegate-able events: not `focus`, `blur`, and
// not `change`, `submit`, and `reset` in Internet Explorer.
The context of this should be your view here, so something else is occurring. 这里的背景应该是你的观点,所以还有其他的东西正在发生。 Could you provide a fiddle with your source?
你可以提供你的来源吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.