-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel-create.html
More file actions
38 lines (38 loc) · 1.14 KB
/
model-create.html
File metadata and controls
38 lines (38 loc) · 1.14 KB
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
33
34
35
36
37
38
<!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>
//first example
var Fruit = Backbone.Model.extend({}); // Create model
var apple = new Fruit({
type: 'apple',
color: 'red',
condition: 'shiny'
});
apple.set('condition', 'bruised'); // set attribute
apple.set({ type: 'banana', color: 'yellow' }); // set multiple attributes
console.log(apple.get('condition') );
console.log(apple.get('type') );
console.log(apple.get('color') );
</script>
<script>
//another example
var Todo = Backbone.Model.extend({});
var todo1 = new Todo();
console.log(JSON.stringify(todo1)); // Logs nothing, since the model contains nothing
var todo2 = new Todo({
title: 'Check the attributes of both model instances in the console.',
completed: true
});
// Emits this error in Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=926595
console.log(JSON.stringify(todo2)); // Logs: {"title":"Check the attributes of both model instances in the console.","completed":true}
</script>
</body>
</html>