-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview-reference-existing.html
More file actions
38 lines (38 loc) · 1 KB
/
Copy pathview-reference-existing.html
File metadata and controls
38 lines (38 loc) · 1 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>
<header>
<div class="welcome-message">Hello</div>
</header>
<div id="user-card"></div>
<script src="jquery-1.11.2.js"></script>
<script src="underscore.js"></script>
<script src="backbone.js"></script>
<script>
var User = Backbone.Model.extend({}); // Create model
var user = new User({ // instantiate model
displayName: 'Russ'
});
var WelcomeMessageView = Backbone.View.extend({
el: 'header .welcome-message', // NOTE THE SPACE!
initialize: function() {
this.model.on('change:displayName', this.render, this); // Makes render() called everytime there is a chnage to displayName
this.render();
},
render: function() {
var displayName = this.model.get('displayName');
this.$el.html('Welcome ' + displayName);
return this;
}
});
var welcomeMessageView = new WelcomeMessageView({
model: user
});
//Use "console.log('displayName', 'Horatio')" to see this in action
</script>
</body>
</html>