在backbone.js 中扩展视图时添加事件处理程序?
我是一名backbone.js n00b,并且无法理解如何扩展视图。我有一个基本的“项目”模型和视图。我想将模型和视图都扩展为“specifiedItem”。有没有办法在扩展视图中添加事件而不是全部替换它们?
项目视图:
var itemView = Backbone.View.extend({
...
events: {
"click" : "foo"
, "dblclick div": "bar"
}
...
});
特定项目视图:
var specificItemView = itemView.extend({
...
// I'd like this to simply add an event handler not replace the ones defined above
events: {
"contextmenu" : "baz"
}
...
});
是否支持以这种方式扩展视图,或者我们只能对模型这样做?
I am a backbone.js n00b and am having trouble understanding how to extend a view. I have a basic "item" model and view. I'd like to extend both the model and view to be "specificItem." Is there a way to add events in the extended view rather than just replace them all?
Item View:
var itemView = Backbone.View.extend({
...
events: {
"click" : "foo"
, "dblclick div": "bar"
}
...
});
Specific Item View:
var specificItemView = itemView.extend({
...
// I'd like this to simply add an event handler not replace the ones defined above
events: {
"contextmenu" : "baz"
}
...
});
Is it even supported to extend views in this way or can we only do that to models?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我没记错的话,扩展不能递归地工作,但你可以自己做。我认为这样的事情应该有效:
这是证明,该扩展不会递归合并
If I'm not mistaken extend does not work recursively, but you can do it yourself. I think something like this should work:
Here is the proof, that extend does not merge recursivly