backbone.js - Get the return elements from the triggered Event in backbone -
i tirggering event. triggered , executed successfully. below code.
itemview = backbone.view.extend({ events: { "click":"onclick" }, onclick: function() { //trigger custom event, passing view first argument events.trigger('click', this); } }); listview = backbone.view.extend({ initialize: function() { this.listento(events, 'click', this._onclick); }, _onclick:function(itemview) { //... return x; } });
but want return data on triggered event. in _onclick want return data.
since doevents.trigger("methodname", parameters). how return data x in above case _onclick function onclick in itemview.
what this:
wrap whatever need in object & use it.
itemview = backbone.view.extend({ events: { "click":"onclick" }, onclick: function() { //trigger custom event, passing view first argument var dataobj = { 'itemview': this, 'otherprop': 'other value' }; events.trigger('click', dataobj); } }); listview = backbone.view.extend({ initialize: function() { this.listento(events, 'click', obj); obj.itemview._onclick(obj); }, _onclick:function(obj) { //... return x; } });
Comments
Post a Comment