infinite-backbone-collection

所属分类:人工智能/神经网络/深度学习
开发工具:CoffeeScript
文件大小:3KB
下载次数:0
上传日期:2013-06-07 21:46:35
上 传 者sh-1993
说明:  Backbone.Collection子类用于Facebook新闻提要的无限分页
(Backbone.Collection subclass for infinite pagination a la Facebook news feed)

文件列表:
infinitelyPaginatedCollection.coffee (2294, 2013-06-08)
infinitelyPaginatedCollection.js (3481, 2013-06-08)

infinite-backbone-collection ============================ Backbone.Collection subclass for infinite pagination a la Facebook news feed. Note that you need to implement server-side handling for retrieving the next/previous results set. ## Configuration options: * resultsPerPage - gets sent as "results_per_page" in the `data` object in the AJAX request * sortColumn - the property of the Backbone.Model that sorting should be done by. This should also be implemented in the same way on the server side * sortDirection - "DESC" or "ASC". Again, should be implemented in the same way on the server side ## Usage Just extend this object instead of the Backbone.Collection object, set the resultsPerPage, sortColumn, and sortDirection properties on the object, and then use fetchNextModels and fetchPreviousModels methods to add models to the collection. ## Example Server-side Code (PHP) public function get_collection() { $results_per_call = $_GET['results_per_call'] ?: 20; if(!empty($_GET['before'])) { $comparator = 'before'; $compared_to = $_GET['before']; } else if(!empty($_GET['after'])) { $comparator = 'after'; $compared_to = $_GET['after']; } else { $comparator = null; $compared_to = null; } if($comparator == 'after') { $results = $db->query("SELECT * FROM table WHERE `timestamp` < ? ORDER BY `timestamp` DESC", $compared_to)->limit($results_per_call)->get(); } elseif($comparator == 'before') { $results = $db->query("SELECT * FROM table WHERE `timestamp` > ? ORDER BY `timestamp` DESC", $compared_to)->limit($results_per_call)->get(); } else { $results = $db->query("SELECT * FROM table ORDER BY `timestamp` DESC")->limit($results_per_call)->get(); } echo json_encode($results); }

近期下载者

相关文件


收藏者