cancel
Showing results for 
Search instead for 
Did you mean: 

Delegates in sapui5

Former Member
0 Kudos

Hi,

what is the use of event delegates in sapui5.? I have seen some examples where they use

this.addEventDelegate({

onAfterRendering : function(e)

{

// some logic

}});

My question is already in the controller we have onAfterRendering hook method which we can make use of, why to explicitly use delegates? I am a  newbie please kindly help.

Thanks

Sushmitha

Accepted Solutions (1)

Accepted Solutions (1)

former_member182862
Active Contributor
0 Kudos

HI Sushmita

addEventDelegate is for the sapui5 view.

Former Member
0 Kudos

Thanks Dennis for the response. But one more question , should we use only standard hook methods like onafterrendering, oninit or onbeforerendering inside event delegate. or can we use any functions like browserevents like onclick etc

former_member182372
Active Contributor
0 Kudos

>.or can we use any functions like browserevents like onclick etc


see the code below. you can add delegate to any event

Former Member
0 Kudos

Hi Maksim,

     Thanks for the quick reply.

Can you please elaborate more with an example?? As I am a newbie, it will be easy for me to understand the concept if you provide an example.

Thanks,

Sushmita

Answers (2)

Answers (2)

former_member182372
Active Contributor
0 Kudos

well, answering your question - delegates support cloning which makes them pretty flexible for list binding - you define a delegate for a template and all the "cloned" objects (the way list binding works) will have the same delegate object

technically this tells you everything

Element.prototype._handleEvent = function (oEvent) {

  var sHandlerName = "on" + oEvent.type;

  this._callEventHandles(this.aBeforeDelegates.slice(0), sHandlerName, oEvent, true);

  this._callEventHandles([this], sHandlerName, oEvent);

  this._callEventHandles(this.aDelegates.slice(0), sHandlerName, oEvent, true);

};

Former Member
0 Kudos

Hi,

How can we remove the bubbling effect of addEventDelagte

I was trying removeEventDelegate but there is no change

Thanks,

Ravali

maheshgonda
Product and Topic Expert
Product and Topic Expert
0 Kudos

hi ,

try this

this.key = jQuery.proxy(this.somefunction,this);

this.addEventDelegate({

onAfterRendering :this.key});

----------------------------------------

to remove

this.removeEventDelegate({

onAfterRendering :this.key});

Former Member
0 Kudos

Hi,

Even after i do removeEventDelegate, timeline.aDelegates is not empty i,e eventDelegate is not getting removed

former_member182372
Active Contributor
0 Kudos

sdk doc is pretty clear

SAPUI5 SDK - Demo Kit