backfire示例中collection add事件的触发问题
来源:互联网 发布:python del函数 编辑:程序博客网 时间:2024/05/24 06:41
backfire是将firebase 绑定到backbone.js的一个库, 随代码提供了一个用backfire实现的todo程序示例。在该示例中程序初始化的时候 并没有显式的触发collection的add事件,代码如下:
initialize: function() { this.input = this.$("#new-todo"); this.allCheckbox = this.$("#toggle-all")[0]; this.listenTo(Todos, 'add', this.addOne); this.listenTo(Todos, 'reset', this.addAll) this.listenTo(Todos, 'all', this.render); this.footer = this.$('footer'); this.main = $('#main');},
那么todo列表是怎么显示出来的呢
在Backbone.Firebase.Collection的_childAdded方法和AppView的initialize方法中分别加入一句调试语句
_childAdded: function(snap) { console.log('child add: ' + (new Date).getTime()); //记录数据开始加入collection的时间 Backbone.Collection.prototype.add.apply(this, [snap.val()]);},
initialize: function() { this.input = this.$("#new-todo"); this.allCheckbox = this.$("#toggle-all")[0]; this.listenTo(Todos, 'add', this.addOne); console.log('listen add: ' + (new Date).getTime()); //记录侦听开始时间 this.listenTo(Todos, 'reset', this.addAll) this.listenTo(Todos, 'all', this.render); this.footer = this.$('footer'); this.main = $('#main');},
输出之后可以发现 child add 在 listen add 之后,这就说明了firebase的数据获取有一定延迟,导致数据加载出现在事件侦听之后, 所以就可以触发侦听的事件了,也就不用显式的触发了。
0 0
- backfire示例中collection add事件的触发问题
- iquery的事件触发问题
- Windows中无法触发DragDrop事件的问题
- NIO中Selector重复触发写事件的问题
- Zepto tap事件中需要触发两次的问题
- jQuery 中事件的触发
- 关于键盘触发事件和屏幕触发事件的问题
- 关于键盘触发事件和屏幕触发事件的问题
- DataGrid中dropdownlist事件的触发/ImageButton的事件触发
- DataGrid中dropdownlist事件的触发ImageButton的事件触发
- 事件代理中冒泡带来的问题----触发根元素自己的事件
- FLEX collection如何触发ChangEvent.COLLECTION_CHANGE事件
- 一个事件被触发两次的问题
- html的onload事件不触发问题
- MouseDragged事件不能触发的问题!
- html的onload事件不触发问题
- 控制事件触发的时机问题
- Android onLongClick事件触发的问题
- 2014年2月7日星期五(7-3,消除了背面的3D线框立方体)
- 【D3DX日记】D3D与D3DX的区别
- 数据库的学习MySQL
- 制造WiFi热点&抓包
- IOS 推送消息 php做推送服务端
- backfire示例中collection add事件的触发问题
- Android编译系统环境初始化过程分析
- Citadel – An Open-Source Malware Project
- 解密中国互联网
- GL音乐播放器--代码实现<四>--进度控制和可隐藏的音量控制
- VMware安装Centos后无法上网
- Win7安装64位CentOS 6.4双系统详细过程
- UML(二)用例图
- 在Cloud9中运行Node Club