|
Answer» You can define views in Backbone.js similar to Backbone models. SEE example below:
SearchView = Backbone.VIEW.extend({ initialize: function(){ alert("WOW! SearchView has been defined."); } });
// The initialize function is always CALLED when instantiating a Backbone View. // CONSIDER it the constructor of the class. var search_view = new SearchView(); //You can specify el property for the view or else it will create EMPTY div and assign it <div id="search_container"></div> var search_view = new SearchView({ el: $("#search_container") }); You can define views in Backbone.js similar to Backbone models. See example below: SearchView = Backbone.View.extend({ initialize: function(){ alert("WOW! SearchView has been defined."); } });
// The initialize function is always called when instantiating a Backbone View. // Consider it the constructor of the class. var search_view = new SearchView(); //You can specify el property for the view or else it will create empty div and assign it <div id="search_container"></div> var search_view = new SearchView({ el: $("#search_container") });
|