forked from clarissalittler/backbone-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathcounter.js
More file actions
33 lines (24 loc) · 715 Bytes
/
counter.js
File metadata and controls
33 lines (24 loc) · 715 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
33
var Counter = Backbone.Model.extend({
defaults : {"value" : 0}
});
var CounterView = Backbone.View.extend({
render: function () {
var val = this.model.get("value");
var btn = '<button>Increment</button>';
this.$el.html('<p>'+val+'</p>' + btn);
}
});
$(document).ready( function () {
var counterModel = new Counter();
var counterView = new CounterView({model : counterModel});
counterView.render();
counterModel.on("change", function () {
counterView.render();
});
counterView.$el.on("click","button", function () {
var mod = counterView.model;
var currVal = mod.get("value");
mod.set("value",currVal+1);
});
$("#counterdiv").append(counterView.$el);
});