Now it is time to start coding the first View component. To help you through the process we are going to lay two basic rules for View coding happiness:
The View should encapsulate a DOM element
Integrate Views with observers
So let's see how they work individually.
As mentioned earlier, a View is the behavior associated with a DOM element, so it makes sense to have this element related to the View. A good pattern is to pass a CSS selector in the View instantiation that indicates the element to which it should refer. Here is the spec for the NewInvestmentView
component:
describe("NewInvestmentView", function() {
var view;
beforeEach(function() {
loadFixtures('NewInvestmentView.html');
view = new NewInvestmentView({selector: '#new-investment'});
});
});
In the constructor function, it uses jQuery to get the element for this selector, and store it in an instance variable $el
(source):
function NewInvestmentView (params...