Skip to content
Advertisement

How can I call the attach / detach events with a named function?

I have a function which needs to attach and detach a handler to the event “requestCompleted” of the OData model to get the URL from the header in order to download the data as an Excel file.

JavaScript

I am trying to detach the event afterwards to prevent snowballing of the event which causes the file to download n+1 times each time you click the download button.


Update: this is the code I ended up with

JavaScript

The detach needs to be within the function otherwise the listener will be detached before the requestCompleted event fires.

Advertisement

Answer

Try this:

model.attachRequestCompleted(this.downloadOdataAsExcel, this);

And then try to access the ‘evt’ object.

Advertisement