Backbone.js: View Cheat Sheet

MethodSyntaxDescription
extendBackbone.View.extend(properties, [classProperties])properties − It provides instance properties for the view class.
classProperties − The classProperties attached to the view’s constructor function.
elview.elIt defines which element to be used as the view reference.
$elview.$elIt represents the jQuery object for the view’s element.
setElementview.setElement(element)It specifies existing DOM element to a different DOM element.
attributesview.attributesThey can be used as DOM element attributes on the view class.
$ (jQuery)view.$(selector)It is used as selector that contains $ function and runs queries within the view’s element.
templateview.template([data])While rendering the view, template creates reusable copies of markup and provides access to instance data.
renderview.render()It contains the logic for rendering a template.
removeview.remove()It is used to remove a view from the dom.
eventsview.events or view.events()The events hash (or method) can be used to specify a set of DOM events that will be bound to methods on your View through delegateEvents.
delegateEventsdelegateEvents([events])It binds elements to the specified DOM elements with callback methods to handle events.
undelegateEventsundelegateEvents()Removes all of the view’s delegated events. Useful if you want to disable or remove a view from the DOM temporarily.

Leave a Reply

Your email address will not be published. Required fields are marked *