Backbone.js的意见delegateEvents没有得到约束(有时) [英] Backbone.js views delegateEvents do not get bound (sometimes)
本文介绍了Backbone.js的意见delegateEvents没有得到约束(有时)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Backbone.js的,有时意见事件没有得到正确绑定。
I'm using Backbone.js and sometimes the views events do not get bound correctly.
我可以检查与 $(视图选择器)。数据()
jQuery的事件绑定的情况。大多数时候有活动,有时也有不!
I can check the event binding situation with $(viewselector).data()
in jQuery. Most of the time there are events, sometimes there aren't!
存在任何已知的东西,我应该注意可能导致此?
Are there any known things I should watch out for that can cause this?
推荐答案
事件委派视图时初始化为this.el。所以,你需要:
Events are delegated to this.el when the view is initialized. So you need to:
- 通过给构造函数的厄尔尼诺选项来指定元素创建视图
- 定义你的看法EL,标签,标识,类名在页面上你的元素直接创建或找到。
- 您的附加渲染视图到视图的厄尔尼诺元素
- 确保您的视图创建后不更换EL元素
有关的最后一个项目,如果你这样做,你可以调用delegateEvents再次对你的看法,重新委托的事件。
For the last item, if you have to do it, you can call delegateEvents once more to re-delegate the event on your view.
这篇关于Backbone.js的意见delegateEvents没有得到约束(有时)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文