Last active
August 29, 2015 14:23
-
-
Save sohelamin/eba4e56846172b5908fc to your computer and use it in GitHub Desktop.
BackboneJS Collection Filtering
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Backbone Model | |
var TaskModel = Backbone.Model.extend({ | |
defaults: { | |
task: '', | |
type: '' | |
} | |
}); | |
// Backbone Collection | |
var TasksCollection = Backbone.Collection.extend({ | |
model: TaskModel, | |
url: 'tasks.json' | |
}); | |
// instantiate a Collection | |
var tasks = new TasksCollection(); | |
tasks.fetch({ | |
success: function () { | |
var TodoCollection = new Backbone.Collection(tasks.where({"type": "todo"})); | |
var DoingCollection = new Backbone.Collection(tasks.where({"type": "doing"})); | |
var DoneCollection = new Backbone.Collection(tasks.where({"type": "done"})); | |
console.log(TodoCollection); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"id": 1, | |
"task": "Create mockups of new iOS app", | |
"type": "doing" | |
}, | |
{ | |
"id": 2, | |
"task": "Build prototype", | |
"type": "todo" | |
}, | |
{ | |
"id": 3, | |
"task": "Alpha-testing", | |
"type": "todo" | |
}, | |
{ | |
"id": 4, | |
"task": "Release beta-version", | |
"type": "todo" | |
}, | |
{ | |
"id": 5, | |
"task": "Collect feedback from beta-users", | |
"type": "todo" | |
}, | |
{ | |
"id": 6, | |
"task": "QA tests", | |
"type": "todo" | |
}, | |
{ | |
"id": 7, | |
"task": "Create blog post", | |
"type": "todo" | |
}, | |
{ | |
"id": 8, | |
"task": "Create email for all iOS users", | |
"type": "todo" | |
}, | |
{ | |
"id": 9, | |
"task": "Update all Sales materials with new mobile app", | |
"type": "todo" | |
}, | |
{ | |
"id": 10, | |
"task": "Fig bugs", | |
"type": "todo" | |
}, | |
{ | |
"id": 11, | |
"task": "Public launch", | |
"type": "todo" | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment