Created
April 25, 2015 21:48
-
-
Save PandaWhisperer/bac31d26c5d3400dcb38 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model = { | |
id: null, // userId, campaignId, etc. | |
selected: false, | |
disabled: false | |
} | |
function EntryView(model) { | |
this.model = model; | |
this.render() | |
this.$el = $( /* div we just rendered */); | |
this.setupEvents(); | |
} | |
EntryView.prototype.render = function() { | |
// re-render based on the current state | |
} | |
EntryView.prototype.clicked = function(evt) { | |
// update selected state | |
this.model.selected != this.model.selected; | |
} | |
EntryView.prototype.setupEvents = function() { | |
// register event handlers | |
this.$el.on('click', this.clicked); | |
// ... | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
filter = { | |
users: { | |
entries: [{ | |
id: 33, | |
selected: false, | |
disabled: false | |
}], | |
disabled: false | |
}, | |
campaigns: { | |
entries: [], | |
disabled: false | |
}, | |
//... | |
} | |
function PickerByView(model) { | |
this.template = Handlebars.compile('template_id'); | |
} | |
PickerByView.prototype.initViews() { | |
this.views = []; | |
for (entry in this.model.entries) { | |
this.views.push(new EntryView(entry)) | |
} | |
} | |
PickerByView.prototype.render() { | |
// render picker | |
// render subviews | |
} | |
function PickerView(filterModel) { | |
} | |
PickerView.prototype.initViews() { | |
this.views = []; | |
for (key in this.filterModel) { | |
this.views.push(new PickerByView(this.filterModel[key])); | |
} | |
} | |
PickerView.prototype.render() { | |
// renders the template using the model | |
var html = this.template(this.model); | |
this.$el.html(html); | |
// render sub views | |
for (var i = 0; i< this.views.length; i++) { | |
this.views[i].render(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment