Lines Matching refs:collection
39 var collection = new Backbone.Collection([
44 assert.deepEqual(collection.pluck('id'), [1, 2, 3]);
57 var collection = new Collection(models, {parse: true});
58 assert.strictEqual(collection.length, 2);
59 assert.strictEqual(collection.first().get('a'), 2);
60 assert.strictEqual(collection.last().get('a'), 4);
68 var collection = new Backbone.Collection([{id: 1}], {
72 collection.add({id: 2});
73 assert.ok(collection.at(0) instanceof Model);
74 assert.ok(collection.at(1) instanceof Model);
75 assert.strictEqual(collection.comparator, comparator);
92 var collection = new Backbone.Collection([model], {model: MongoModel});
93 assert.equal(collection.get(100), model);
94 assert.equal(collection.get(model.cid), model);
95 assert.equal(collection.get(model), model);
96 assert.equal(collection.get(101), void 0);
126 var collection = new Backbone.Collection();
127 collection.add([
131 var one = collection.get(0);
133 collection.on('change:name', function(model) { assert.ok(this.get(model)); });
135 assert.equal(collection.get(0), null);
136 assert.equal(collection.get(101).get('name'), 'dalmatians');
159 col.on('add', function(model, collection, options){ argument
196 var collection = new Backbone.Collection([{at: 0}, {at: 1}, {at: 9}]);
197 collection.add([{at: 2}, {at: 3}, {at: 4}, {at: 5}, {at: 6}, {at: 7}, {at: 8}], {at: 2});
199 assert.equal(collection.at(i).get('at'), i);
211 var collection = new Col([{id: 2}, {id: 3}]);
212 collection.add(new Backbone.Model({id: 1}), {at: 1});
214 assert.equal(collection.pluck('id').join(' '), '3 1 2');
219 var collection = new Backbone.Collection([{id: 2}, {id: 3}]);
220 collection.add(new Backbone.Model({id: 1}), {at: 5});
222 assert.equal(collection.pluck('id').join(' '), '2 3 1');
226 var collection = new Backbone.Collection([{id: 1}, {id: 2}, {id: 1}, {id: 2}, {id: 3}]);
227 assert.equal(collection.pluck('id').join(' '), '1 2 3');
232 var collection = new Backbone.Collection;
233 collection.unshift({id: 101});
234 collection.add({id: 101});
235 assert.equal(collection.length, 1);
240 var collection = new Backbone.Collection;
241 collection.add([{id: 1, name: 'Moe'}, {id: 2, name: 'Curly'}, {id: 3, name: 'Larry'}]);
242 collection.add({id: 1, name: 'Moses'});
243 assert.equal(collection.first().get('name'), 'Moe');
244 collection.add({id: 1, name: 'Moses'}, {merge: true});
245 assert.equal(collection.first().get('name'), 'Moses');
246 collection.add({id: 1, name: 'Tim'}, {merge: true, silent: true});
247 assert.equal(collection.first().get('name'), 'Tim');
254 m.on('add', function(model, collection) { argument
258 assert.equal(collection, col2);
260 assert.equal(collection, col1);
264 col1.on('add', function(model, collection) { argument
266 assert.equal(col1, collection);
269 col2.on('add', function(model, collection) { argument
271 assert.equal(col2, collection);
274 assert.equal(m.collection, col1);
276 assert.equal(m.collection, col1);
289 var collection = new Col;
290 collection.add({value: 1}, {parse: true});
291 assert.equal(collection.at(0).get('value'), 2);
295 var collection = new Backbone.Collection();
296 collection.parse = function(attrs) {
302 collection.add({id: 1});
303 collection.add({model: {id: 1, name: 'Alf'}}, {parse: true, merge: true});
304 assert.equal(collection.first().get('name'), 'Alf');
309 var collection = new Backbone.Collection;
310 collection.comparator = function(m1, m2) {
316 collection.add(tom);
317 collection.add(rob);
318 collection.add(tim);
319 assert.equal(collection.indexOf(rob), 0);
320 assert.equal(collection.indexOf(tim), 1);
321 assert.equal(collection.indexOf(tom), 2);
326 var collection = new Backbone.Collection;
327 collection.negative = function(num) {
330 collection.comparator = function(model) {
333 collection.add([{id: 1}, {id: 2}, {id: 3}]);
334 assert.deepEqual(collection.pluck('id'), [3, 2, 1]);
335 collection.comparator = function(m1, m2) {
338 collection.sort();
339 assert.deepEqual(collection.pluck('id'), [1, 2, 3]);
346 col.on('remove', function(model, collection, options) { argument
349 … assert.equal(collection.get(model), undefined, '#3693: model cannot be fetched from collection');
377 var collection = new Backbone.Collection;
378 collection.model = Even;
380 var list = collection.add([{id: 2}, {id: 4}], {validate: true});
383 assert.equal(list[1], collection.last());
386 list = collection.add([{id: 3}, {id: 6}], {validate: true});
387 assert.equal(collection.length, 3);
391 var result = collection.add({id: 6});
394 result = collection.remove({id: 6});
395 assert.equal(collection.length, 2);
398 list = collection.remove([{id: 2}, {id: 8}]);
399 assert.equal(collection.length, 1);
406 var collection = new Backbone.Collection([{a: 'a'}, {b: 'b'}, {c: 'c'}]);
407 assert.equal(collection.shift().get('a'), 'a');
408 assert.equal(collection.pop().get('c'), 'c');
413 var collection = new Backbone.Collection([{a: 'a'}, {b: 'b'}, {c: 'c'}]);
414 var array = collection.slice(1, 3);
428 assert.equal(dj.collection, undefined);
462 m.on('remove', function(model, collection) { argument
466 assert.equal(collection, col1);
468 assert.equal(collection, col2);
472 col1.on('remove', function(model, collection) { argument
474 assert.equal(col1, collection);
477 col2.on('remove', function(model, collection) { argument
479 assert.equal(col2, collection);
481 assert.equal(col1, m.collection);
486 assert.equal(col1, m.collection);
488 assert.equal(null, m.collection);
502 assert.equal(undefined, m.collection);
514 assert.equal(undefined, m.collection);
519 var collection = new Backbone.Collection;
520 collection.url = '/test';
521 collection.fetch();
523 assert.equal(this.syncArgs.model, collection);
526 collection.fetch({parse: false});
532 var collection = new Backbone.Collection();
533 collection.on('error', function() {
536 collection.sync = function(method, model, options) { options.error(); };
537 collection.fetch();
542 var collection = new Backbone.Collection();
550 collection.sync = function(method, model, opts) {
553 collection.fetch(options);
558 var collection = new Backbone.Collection;
560 collection.parse = function(models) {
564 collection.url = '/test';
565 collection.fetch();
572 var collection = new Backbone.Collection;
573 collection.url = '/test';
574 var model = collection.create({label: 'f'}, {wait: true});
578 assert.equal(model.collection, collection);
591 var collection = new ValidatingCollection();
592 collection.on('invalid', function(coll, error, options) {
596 assert.equal(collection.create({foo: 'bar'}, {validate: true}), false);
613 var collection = new Collection;
619 collection.create({}, {success: success});
632 var collection = new Collection;
634 collection.create({}, {wait: true});
647 var collection = new ValidatingCollection();
648 var m = collection.create({foo: 'bar'});
650 assert.equal(collection.length, 1);
818 var collection = new Backbone.Collection({id: 1});
819 collection.reset({id: 1, a: 1});
820 assert.equal(collection.get(1).get('a'), 1);
825 var collection = new Backbone.Collection({id: 1});
826 collection.reset(model);
827 assert.equal(collection.get(1), model);
837 var collection = new (Backbone.Collection.extend({model: Model}))();
838 …collection.reset([{astring: 'green', anumber: 1}, {astring: 'blue', anumber: 2}], {modelParameter:…
839 assert.equal(collection.length, 2);
840 collection.each(function(model) {
847 var collection = new Backbone.Collection([{id: 1}]);
849 collection.on('reset', function(coll, opts){
853 collection.reset([], origOpts);
875 var collection = new Backbone.Collection;
876 collection.url = '/test';
880 assert.equal(this.collection, collection);
884 collection.model = Model;
885 collection.create({prop: 'value'});
890 var collection = new Backbone.Collection([
893 assert.equal(collection.length, 6);
894 collection.remove(collection.models);
895 assert.equal(collection.length, 0);
910 var collection = new Collection;
911 collection.on('invalid', function() { assert.ok(true); });
913 collection.add([{id: 1}, {id: 2}, {id: 3}, {id: 4}, {id: 5}, {id: 6}], {validate: true});
914 assert.deepEqual(collection.pluck('id'), [1, 2, 4, 5, 6]);
919 var collection = new Backbone.Collection;
920 collection.on('test', function() { assert.ok(true); });
921 collection.model = Backbone.Model.extend({
924 var model = new collection.model({id: 1, valid: true});
925 collection.add([model, {id: 2}], {validate: true});
927 assert.ok(collection.get(model.cid));
928 assert.ok(collection.get(1));
929 assert.ok(!collection.get(2));
930 assert.equal(collection.length, 1);
935 var collection = new Backbone.Collection();
937 collection.add([model, model]);
938 assert.equal(collection.length, 1);
939 collection.add([{id: 1}, {id: 1}]);
940 assert.equal(collection.length, 2);
941 assert.equal(collection.last().id, 1);
946 var collection = new Backbone.Collection();
947 assert.ok(collection.get(null) === undefined);
948 assert.ok(collection.get() === undefined);
954 var collection = new Backbone.Collection([{id: 1}], {model: Model});
955 assert.ok(collection.model === Model);
956 assert.ok(collection.at(0) instanceof Model);
962 var collection = new Backbone.Collection([model]);
964 assert.ok(!collection.get('null'));
967 assert.ok(!collection.get('undefined'));
975 var collection = new Col();
979 assert.ok(collection.comparator);
988 var collection = new Backbone.Collection();
995 collection.sync = m.sync = function( method, coll, options ){
998 collection.fetch(opts);
999 collection.create(m, opts);
1004 var collection = new Backbone.Collection;
1005 collection.url = '/test';
1008 collection.on('request', function(obj, xhr, options) {
1009 assert.ok(obj === collection, "collection has correct 'request' event after fetching");
1011 collection.on('sync', function(obj, response, options) {
1012 assert.ok(obj === collection, "collection has correct 'sync' event after fetching");
1014 collection.fetch();
1015 collection.off();
1017 collection.on('request', function(obj, xhr, options) {
1018 …assert.ok(obj === collection.get(1), "collection has correct 'request' event after one of its mode…
1020 collection.on('sync', function(obj, response, options) {
1021 …assert.ok(obj === collection.get(1), "collection has correct 'sync' event after one of its models …
1023 collection.create({id: 1});
1024 collection.off();
1029 var collection = new Backbone.Collection;
1030 collection.url = '/test';
1042 collection.fetch(options);
1043 collection.create({id: 1}, options);
1048 var collection = new Backbone.Collection;
1051 collection.on('add', function(){ assert.ok(true); });
1052 collection.create(model, {wait: true});
1057 var collection = new Backbone.Collection([
1061 collection.comparator = function(model){ return model.get('x'); };
1062 collection.add({id: 1, x: 3}, {merge: true});
1063 assert.deepEqual(collection.pluck('id'), [2, 1]);
1068 var collection = new Backbone.Collection([{x: 1}, {x: 2}]);
1069 var grouped = collection.groupBy('x');
1077 var collection = new Backbone.Collection([{x: 3}, {x: 1}, {x: 2}]);
1078 var values = _.map(collection.sortBy('x'), function(model) {
1086 var collection = new Backbone.Collection([{}, {}]);
1087 collection.on('add', function() {
1088 collection.at(0).destroy();
1090 collection.add({}, {at: 0});
1094 var collection = new Backbone.Collection;
1095 collection.comparator = function(model) { return model.get('x'); };
1097 collection.on('add', function(model) {
1099 collection.sort();
1102 collection.add([{id: 1, x: 1}, {id: 2, x: 2}]);
1123 var collection = new Backbone.Collection([{id: 1}, {id: 2}, {id: 3}], {
1126 collection.sort = function(){ assert.ok(true); };
1127 collection.add([]);
1128 collection.add({id: 1});
1129 collection.add([{id: 2}, {id: 3}]);
1130 collection.add({id: 4});
1149 var collection = new Collection(model, {parse: true});
1151 assert.equal(collection.length, 2);
1152 assert.equal(collection.at(0).get('name'), 'test');
1171 var collection = new Collection();
1172 collection.reset(model, {parse: true});
1174 assert.equal(collection.length, 2);
1175 assert.equal(collection.at(0).get('name'), 'test');
1182 var collection = new Backbone.Collection([model]);
1183 collection.on('reset', function(coll, options) {
1186 collection.reset([]);
1193 var collection = new Backbone.Collection([m1, m2]);
1196 collection.on('add', function(model) {
1199 collection.on('change', function(model) {
1202 collection.on('remove', function(model) {
1207 collection.set([], {remove: false});
1208 assert.strictEqual(collection.length, 2);
1211 collection.set([m1, m2, m3], {add: false});
1212 assert.strictEqual(collection.length, 2);
1215 collection.set([m1, {id: 2, a: 1}], {merge: false});
1219 collection.set([m1, {id: 2, a: 0}, m3, {id: 4}], {add: false, remove: false});
1220 assert.strictEqual(collection.length, 2);
1224 collection.set([{id: 2, a: 1}, m3]);
1225 assert.strictEqual(collection.length, 2);
1229 collection.off('remove').on('remove', function(model) {
1232 collection.set([]);
1233 assert.strictEqual(collection.length, 0);
1236 collection.off();
1237 collection.set([{id: 1}]);
1238 collection.set();
1239 assert.strictEqual(collection.length, 1);
1246 var collection = new Backbone.Collection;
1247 collection.set([m1, m2]);
1248 assert.equal(collection.length, 2);
1249 collection.set([m1]);
1250 assert.equal(collection.length, 1);
1251 collection.set([m1, m1, m1, m2, m2], {remove: false});
1252 assert.equal(collection.length, 2);
1264 var collection = new Col;
1265 collection.set([m1, m2]);
1266 assert.equal(collection.length, 2);
1267 collection.set([m1]);
1268 assert.equal(collection.length, 1);
1269 collection.set([m1, m1, m1, m2, m2], {remove: false});
1270 assert.equal(collection.length, 2);
1280 var collection = new Backbone.Collection([m], {model: Model});
1281 assert.equal(collection.first().get('key'), 'value');
1283 collection.set({id: 1, key: 'other'});
1284 assert.equal(collection.first().get('key'), 'other');
1286 collection.set({id: 1, other: 'value'});
1287 assert.equal(collection.first().get('key'), 'other');
1288 assert.equal(collection.length, 1);
1301 var collection = new Collection(data);
1302 assert.equal(collection.first().id, 1);
1303 collection.set(data);
1304 assert.equal(collection.first().id, 1);
1305 collection.set([{id: 2, child: {id: 2}}].concat(data));
1306 assert.deepEqual(collection.pluck('id'), [2, 1]);
1316 var collection = new Collection(model);
1317 collection.set({models: [
1321 assert.equal(collection.first(), model);
1325 var collection = new Backbone.Collection();
1326 collection.model = Backbone.Model.extend({
1333 collection.set({}, {parse: true});
1340 var collection = new Backbone.Collection([one, two, three]);
1341 collection.set([{id: 3}, {id: 2}, {id: 1}]);
1342 assert.deepEqual(collection.models, [three, two, one]);
1343 collection.set([{id: 1}, {id: 2}]);
1344 assert.deepEqual(collection.models, [one, two]);
1345 collection.set([two, three, one]);
1346 assert.deepEqual(collection.models, [two, three, one]);
1347 collection.set([{id: 1}, {id: 2}], {remove: false});
1348 assert.deepEqual(collection.models, [two, three, one]);
1349 collection.set([{id: 1}, {id: 2}, {id: 3}], {merge: false});
1350 assert.deepEqual(collection.models, [one, two, three]);
1351 collection.set([three, two, one, {id: 4}], {add: false});
1352 assert.deepEqual(collection.models, [one, two, three]);
1366 var collection = new Backbone.Collection;
1367 var model1 = collection.push({id: 101});
1368 var model2 = collection.push({id: 101});
1376 var collection = new Collection({_id: 1});
1377 collection.set([{_id: 1, a: 1}], {add: false});
1378 assert.equal(collection.first().get('a'), 1);
1391 var collection = new (Backbone.Collection.extend({
1398 collection.set(res, {parse: true});
1404 var collection = new (Backbone.Collection.extend({
1416 collection.fetch({
1426 sync: function(method, collection, options) { argument
1428 return Backbone.Collection.prototype.sync.call(this, method, collection, options); argument
1432 var collection = new SpecialSyncCollection();
1438 collection.fetch({success: onSuccess});
1444 var collection = new (Backbone.Collection.extend({
1447 collection.on('sort', function() { assert.ok(true); });
1448 collection.add({id: 4}); // do sort, new model
1449 collection.add({id: 1, a: 1}, {merge: true}); // do sort, comparator change
1450 collection.add({id: 1, b: 1}, {merge: true}); // don't sort, no comparator change
1451 collection.add({id: 1, a: 1}, {merge: true}); // don't sort, no comparator change
1452 collection.add(collection.models); // don't sort, nothing new
1453 collection.add(collection.models, {merge: true}); // don't sort
1458 var collection = new (Backbone.Collection.extend({
1463 collection.on('sort', function() { assert.ok(true); });
1464 collection.add({id: 4}); // do sort, new model
1465 collection.add({id: 1, a: 1}, {merge: true}); // do sort, model change
1466 collection.add({id: 1, b: 1}, {merge: true}); // do sort, model change
1467 collection.add({id: 1, a: 1}, {merge: true}); // don't sort, no model change
1468 collection.add(collection.models); // don't sort, nothing new
1469 collection.add(collection.models, {merge: true}); // don't sort
1477 var collection = new Backbone.Collection([], {
1482 assert.ok(collection.model === Model);
1483 assert.ok(collection.comparator === comparator);
1497 var collection = new Collection(falsey, opts);
1498 assert.strictEqual(collection.length, 0);
1503 var collection = new Backbone.Collection();
1504 collection.once('add', function(model, coll, options) {
1507 collection.set({id: 1});
1508 assert.equal(collection.length, 2);
1513 var collection = new Backbone.Collection;
1514 collection.url = 'test';
1515 collection.create({}, {
1625 assert.equal(model.collection, void 0);
1630 var collection = new Collection();
1631 var model = collection.add({id: 1});
1632 collection.remove(model);
1639 var collection = new Backbone.Collection();
1641 collection.add([{id: 1}, {id: 1}]);
1642 assert.equal(collection.length, 1);
1643 assert.equal(collection.models.length, 1);
1645 collection.set([{id: 1}, {id: 1}]);
1646 assert.equal(collection.length, 1);
1647 assert.equal(collection.models.length, 1);
1652 var collection = new Backbone.Collection;
1653 collection.set([{id: 1}], {add: false});
1654 assert.strictEqual(collection.length, 0);
1655 assert.strictEqual(collection.models.length, 0);
1660 var collection = new Backbone.Collection();
1663 assert.equal(this.collection, collection);
1665 collection.create(model, {wait: true});
1686 var collection = new C([{id: 1, type: 'a'}, {id: 2, type: 'b'}]);
1687 assert.equal(collection.length, 2);
1688 assert.ok(collection.at(0) instanceof A);
1689 assert.equal(collection.at(0).id, 1);
1690 assert.ok(collection.at(1) instanceof B);
1691 assert.equal(collection.at(1).id, 2);
1706 var collection = new C([{_id: 1, type: 'a'}, {_id: 2, type: 'b'}]);
1707 assert.equal(collection.length, 2);
1708 assert.ok(collection.at(0) instanceof A);
1709 assert.equal(collection.at(0), collection.get(1));
1710 assert.ok(collection.at(1) instanceof B);
1711 assert.equal(collection.at(1), collection.get(2));
1722 collection = new C([{id: 1, type: 'a'}, {id: 1, type: 'b'}]);
1723 assert.equal(collection.length, 2);
1724 assert.ok(collection.at(0) instanceof A);
1725 assert.equal(collection.at(0), collection.get('a-1'));
1726 assert.ok(collection.at(1) instanceof B);
1727 assert.equal(collection.at(1), collection.get('b-1'));
1763 var collection = new Backbone.Collection([{val: 0}, {val: 4}]);
1764 collection.on('add', function(model, coll, options) {
1767 collection.add([{val: 1}, {val: 2}, {val: 3}], {at: 1});
1768 collection.add({val: 5}, {at: 10});
1773 var collection = new Backbone.Collection([{at: 0}]);
1774 collection.on('add', function(model, coll, options) {
1777 collection.add([{at: 1}, {at: 2}]);
1785 var collection = new Backbone.Collection([one, two, three]);
1786 collection.on('sort', function() {
1789 collection.set([{id: 3}, {id: 2}, {id: 1}]);
1797 var collection = new Backbone.Collection([one, two, three]);
1798 collection.on('sort', function() {
1801 collection.set([{id: 1}, {id: 2}, {id: 3}, {id: 0}]);
1809 var collection = new Backbone.Collection([one, two, three]);
1810 collection.on('sort', function() {
1813 collection.set([{id: 1}, {id: 2}, {id: 3}]);
1818 var collection = new Backbone.Collection([{id: 1}]);
1819 collection.add([{id: 2}, {id: 3}], {at: -1});
1820 collection.add([{id: 2.5}], {at: -2});
1821 collection.add([{id: 0.5}], {at: -6});
1822 assert.equal(collection.pluck('id').join(','), '0.5,1,2,2.5,3');
1827 var collection = new Backbone.Collection([{id: 1}, {id: 2}]);
1828 collection.add([{id: 3}], {at: '1'});
1829 assert.deepEqual(collection.pluck('id'), [1, 3, 2]);
1834 var collection = new Backbone.Collection;
1835 collection.on('update', function() { assert.ok(true); });
1836 collection.add([{id: 1}, {id: 2}, {id: 3}]);
1841 var collection = new Backbone.Collection([{id: 1}, {id: 2}, {id: 3}]);
1842 collection.on('update', function() { assert.ok(true); });
1843 collection.remove([{id: 1}, {id: 2}]);
1848 var collection = new Backbone.Collection([{id: 1}, {id: 2}]);
1849 collection.on('update', function() { assert.ok(false); });
1850 collection.remove([{id: 3}]);
1855 var collection = new Backbone.Collection([{id: 1}, {id: 2}]);
1856 collection.on('update', function() { assert.ok(true); });
1857 collection.set([{id: 1}, {id: 3}]);
1861 var collection = new Backbone.Collection([{id: 1}, {id: 2}]);
1862 collection.on('update', function(coll, options) {
1867 collection.set([{id: 1}, {id: 2}]);
1882 var collection = new Collection([{id: 1}]);
1883 collection.invoke('method', 1, 2, 3);
1888 var collection = new Backbone.Collection([{id: 1}]);
1889 var model = collection.first();
1890 collection.on('change', function(m) {
1897 var collection = new (Backbone.Collection.extend({
1900 collection.set('', {parse: true});
1901 assert.equal(collection.length, 0);
1906 var collection = new Backbone.Collection([model]);
1907 collection.on('update', function(context, options) {
1913 collection.remove(model);
1919 var collection = new Backbone.Collection([model, model2]);
1920 collection.on('update', function(context, options) {
1928 collection.remove([model, model2]);
1933 var collection = new Backbone.Collection();
1934 collection.on('update', function(context, options) {
1939 collection.set(model);
1945 var collection = new Backbone.Collection();
1946 collection.on('update', function(context, options) {
1952 collection.set([model, model2]);
1959 var collection = new Backbone.Collection([model]);
1960 collection.on('update', function(context, options) {
1967 collection.set([model2, model3]);
1974 var collection = new Backbone.Collection([model, model2]);
1975 collection.on('update', function(context, options) {
1981 collection.set([model3]);
1988 var collection = new Backbone.Collection([model, model2]);
1989 collection.on('update', function(context, options) {
1994 collection.set([model2Update]);
2002 var collection = new Backbone.Collection([model, model2]);
2003 collection.on('update', function(context, options) {
2009 collection.set([model2Update, modelUpdate]);
2015 var collection = new Backbone.Collection([model]);
2016 collection.on('update', function(context, options) {
2019 collection.set([model]);