Backbone forms

Now that we have the base Backbone application up and running, we can make a few tweaks to include a form at the bottom of the page, and show how to get and set form values within our View. This form will be handled by the ItemCollectionView class and, as such, we will need to update our model with a new property, as follows:

class ItemCollectionViewModel extends Backbone.Model 
    implements IItemCollectionViewModel { 
 
    ... existing properties  
 
    set Name(value: string) { 
        this.set('Name', value); 
    } 
    get Name() { 
        return this.get('name'); 
    } 
 
    ... existing constructor 
 
} 

Here, we have simply added a matching pair of ES5 get and set functions to store and retrieve our Name property. Once this change is made, we will also need to set this ...

Get Mastering TypeScript 3 - Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.