handlebars.js 使用心得(1)
来源:互联网 发布:狗万万博软件 编辑:程序博客网 时间:2024/05/17 18:14
在项目开发中,遇到一个问题,描述如下:
1、展示一个列表;
2、列表每页20个,下拉到底部加载更多;
问题是:
1、如何确定到了底部;
2、如何确定页面已经加载了全部的内容;
问题1
使用了jauery组件lazyload(http://www.appelsiini.net/projects/lazyload);
问题2
全部数据存储在一个collection中,
var xCollection = Backbone.Collection.extend();
每个数据item是一个model
var xModel = Backbone.Model.extend();
解决方案是:获取collection时,直接返回所有的item和全部的total总数,问题在于,如何处理结果来将结果中的值正确的放到collection中,
返回结果结构:
var xM = {data:[{a:1, b:2}, {a:3, b:4}], total:20};
我采用的是custom collection的set、add、reset方法,测试代码如下:
var xModel = Backbone.Model.extend();var xCollection = Backbone.Collection.extend({ model: xModel, total: 0, set: function(attributes, options) { console.log('set'); console.log(attributes); console.log(options); if (attributes.total) { this.total = attributes.total; } if (attributes.data) { attributes = attributes.data; } return Backbone.Collection.prototype.set.call(this, attributes, options); }, add: function(attributes, options) { console.log('add'); console.log(attributes); console.log(options); if (attributes.total) { this.total = attributes.total; } if (attributes.data) { attributes = attributes.data; } return Backbone.Collection.prototype.add.call(this, attributes, options); }});var xM = {data:[{a:1, b:2}, {a:3, b:4}], total:20};var xM1 = {data:[{a:5, b:6}, {a:7, b:8}], total:40};var xC1 = new xCollection();
set测试结果:
xC1.set(xM);
结果是:
set Object {data: Array[2], total: 20}undefinedchild {length: 2, models: Array[2], _byId: Object, total: 20, constructor: function…}
add测试结果:
xC1.add(xM1);
结果是:
add Object {data: Array[2], total: 40}undefined set[Object, Object]Object {add: true, merge: false, remove: false}child {length: 4, models: Array[4], _byId: Object, total: 40, constructor: function…}
0 0
- handlebars.js 使用心得(1)
- Handlebars.js 使用入门
- handlebars.js 入门(1)
- Handlebars.js的下载及使用示例
- 浅析Handlebars.js的使用流程
- 【h1】handlebars.js使用时渲染空白
- handlebars使用
- JavaScript页面模版引擎handlebars.js学习及使用
- handlebars.js模版引擎中EACH循环遍历的使用
- Handlebars js模版
- Handlebars js模版
- Handlebars.js 中文文档
- handlebars.js笔记
- Handlebars.js 模板引擎
- 模板引擎 Handlebars.js
- Handlebars.js 表达式
- Handlebars.js 预编译
- Handlebars.js 中文文档
- backbone.js使用心得
- 如何正确配置Nginx+PHP
- Struts2.1 annotation防止表单重复提交
- jquery-ajax-queue使用心得
- Yarn 2.2.0安装
- handlebars.js 使用心得(1)
- 【最终版 & 总结】自实现自旋锁 与 mutex,spinlock比较(结果令人吃惊)
- struts2中form提交到action中的中文参数乱码问题解决办法(包括取中文路径)
- Object-C内存管理
- Android应用开发SharedPreferences存储数据的使用方法
- 模式实践:观察者模式与Spring
- 用Struts2中的ActionSupport中的validate方法进行表单验证
- 第五项修炼之我见
- 做一个合格的seoer是需要对客户负责的,不是仅仅只合同上的任务