Anton Shestakov <engored@ya.ru>, Fri, 14 Dec 2012 23:54:33 +0900
Changes for Backbone 0.9.9: Shards now also proxy Underscore method name aliases.
demo.html
Permissions: -rw-r--r--
<title>Shard Demo
</title> <link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet"> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.2/underscore-min.js"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js"></script> <script src="backbone.shard.js"></script> <div class="span3 offset5"> <div id="collection"></div> <div class="span3 offset3"> <div id="subset-read" class="centered"></div> <div class="span3 offset1"> <div id="subset-unread" class="centered"></div> var Book = Backbone.Model; var col = new Backbone.Collection([ new Book({title: 'Crime and Punishment', read: true}), new Book({title: 'Robinson Crusoe', read: true}), new Book({title: 'Moby Dick', read: false}), new Book({title: 'The Catcher in the Rye', read: false}) var CollectionView = Backbone.View.extend({ initialize: function(options) { this.collection.on('add change remove reset', this.render, this); this.collection.each(this.appendItem, this); appendItem: function(item) { var $cb = $('<input>').attr('type', 'checkbox').prop('checked', item.get('read')); var $label = $('<label>').addClass('checkbox').text(item.get('title')).prepend($cb); item.set('read', this.checked); var shardRead = new Backbone.Shard({collection: col, filter: function(book) { return book.get('read'); } }); var shardUnread = new Backbone.Shard({collection: col, filter: function(book) { return !book.get('read'); } });