javascript - Backbone.View.extend - events hash -
i'm going through tutorial advises events can captured via view follows:
var view = backbone.view.extend({ el: $('#element'), events: {}, render: function(){} });
there doesn't seem documentation associated events object. has been deprecated or obsolete? or looking in wrong place: http://backbonejs.org/
from view.delegateevents
delegateevents delegateevents([events])
uses jquery'son
function provide declarative callbacks dom events within view. if events hash not passed directly, usesthis.events
source. events written in format{"event selector": "callback"}
. callback may either name of method on view, or direct function body. omitting selector causes event bound view's root element (this.el
). default,delegateevents
called within view's constructor you, if have simple events hash, of dom events connected, , never have call function yourself.the events property may defined function returns events hash, make easier programmatically define events, inherit them parent views.
using
delegateevents
provides number of advantages on manually using jquery bind events child elements during render. attached callbacks bound view before being handed off jquery, when callbacks invoked, continues refer view object. whendelegateevents
run again, perhaps different events hash, callbacks removed , delegated afresh — useful views need behave differently when in different modes.
Comments
Post a Comment