var data, tasks, filterset, filtered, catTasks, catFiltered
data = [{
'title': 'foo',
'complete': false
}, {
'title': 'bar',
'complete': false
}, {
'title': 'baz',
'complete': false
}, {
'title': 'qux',
'complete': true
}, {
'title': 'dog',
'complete': true
}, {
'title': 'cat',
'complete': true
}];
// create a master collection (tasks)
// create a filtered set (filterset)
// create a new collection from filterset (filtered)
tasks = new Backbone.Collection(data);
filterset = tasks.where({complete: true});
filtered = new Backbone.Collection(filterset);
// get two references to two models that we know exist in both collections
catTasks = tasks.findWhere({title: 'cat'});
catFiltered = filtered.findWhere({title: 'cat'});
// log out the current models len for both collections
// the cid for both model refs (should be identical)
// test to see if they are equal (should be true)
console.log('collection model length: ', tasks.models.length, filtered.models.length);
console.log('model cids: ', catTasks.cid, catFiltered.cid);
console.log('models are equal: ', catTasks === catFiltered);
// destroy the filtered model
// this should propagate through both collections
catFiltered.destroy();
// log out that the collection len has changed for both coll.
console.log('collection model length has changed: ', tasks.models.length, filtered.models.length);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.