February 2019
Beginner
694 pages
18h 4m
English
As mentioned earlier, we will need to build two views. The first view is named ItemView, and will be used to render a single button to the DOM. As such, it is tied to a single ItemModel in our collection. Let's take a look at this ItemView class, as follows:
class ItemView extends Backbone.View<ItemModel> { template: (json: any, options?: any) => string; constructor( options = <Backbone.ViewOptions<ItemModel>>{} ) { options.events = { 'click': 'onClicked' }; super(options); let templateSnippet = $(`#itemViewTemplate`).html(); this.template = _.template(templateSnippet); _.bindAll(this, 'onClicked'); } render() { this.$el.html( this.template(this.model.attributes) ); return this; } onClicked() { EventBus.Bus.trigger("item_clicked", ...Read now
Unlock full access