-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollection-sortBy.html
More file actions
32 lines (32 loc) · 848 Bytes
/
Copy pathcollection-sortBy.html
File metadata and controls
32 lines (32 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script src="jquery-1.11.2.js"></script>
<script src="underscore.js"></script>
<script src="backbone.js"></script>
<script>
var todos = new Backbone.Collection();
todos.add([
{ title: 'go to China.', completed: false },
{ title: 'go to Belgium.', completed: false },
{ title: 'go to Austria.', completed: true }
]);
var sortedByAlphabet = todos.sortBy(function (todo) { // use sortBy() to re-order the models
return todo.get("title").toLowerCase();
});
console.log("- Now sorted: ");
sortedByAlphabet.forEach(function(model){ // use foreach to log each to console
console.log(model.get('title'));
});
// Above logs:
// - Now sorted:
// go to Austria.
// go to Belgium.
// go to China.
</script>
</body>
</html>