-
Notifications
You must be signed in to change notification settings - Fork 220
/
Copy pathapple.view.js
27 lines (23 loc) · 890 Bytes
/
apple.view.js
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
const appleView = Backbone.View.extend({
initialize: function(){
this.model = new (Backbone.Model.extend({}))
this.model.on('change', this.render, this)
this.on('spinner', this.showSpinner, this)
},
template: _.template(appleTpl),
templateSpinner: appleSpinnerTpl,
loadApple:function(appleName){
this.trigger('spinner')
const view = this //we'll need to access that inside of a closure
setTimeout(function(){ //simulates real time lag when fetching data from the remote server
view.model.set(view.collection.where({name:appleName})[0].attributes)
}, 1000)
},
render: function(appleName){
const appleHtml = this.template(this.model)
$('body').html(appleHtml)
},
showSpinner: function(){
$('body').html(this.templateSpinner)
}
})