模型更改后backbone.js事件未绑定?
这是视图初始化中的代码:
var self = this
this.model.bind('change', function () {
self.render();
});
我定义了一堆事件:
events: {
"click #blah": "blah",
},
但是在更改模型并重新渲染视图之后,事件不再绑定?
我可以通过在渲染中放置 this.delegateEvents()
来绑定它们,但我认为这样做不正确。
我做错了什么吗?
Here's the code in the view initialize:
var self = this
this.model.bind('change', function () {
self.render();
});
I have a bunch of events defined:
events: {
"click #blah": "blah",
},
But after changing the model and re-rendering the view the events are no longer bound?
I can bind them by putting a this.delegateEvents()
in the render, but I don't think that's doing it correctly.
Am I doing something wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否在视图中设置了 el 属性?事件被委托给这个 el。
Did you set the el property in your view? The events are delegated to this el.