.png)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Working with the getData() function
Hello all,
I am developing a mashup where I will be using the API to collect data with the getData method (in particular field.getData()). From what I gather from experimentation and the API, if I want to work with the data that I receive from getData I will need to wait for the "OnData" notification.
From what I can tell, "OnData" is a function that is called whenever the data is refreshed. The API (as far as I can tell) has no real details about it. They suggest to bind a listener function to OnData. So, something like this.
field.getData().OnData.bind(mylistener)
Within "mylistener" the "this" keyword will be the returned data from the getData function. That's okay, but what I really want is to be able to retain "this" at the scope of my class (using ES6). As far as I can tell at this moment, when I am in my listener function I have no way to save the data where it needs to go because this is being re-purposed to store the qlik data.
Any ideas about how to do this without having to do some kind of hacky search through global variables?
Jonathan
.png)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I really don't know how this works because the API documentation is sketchy, but using vanilla javascript with no ES6 notation ("let" keyword, arrow functions, etc). I got this to do what I want:
var aCopyOfTheVariableIWantToFill = this.theVariableIWantToFill;
this.$qlikOpenApp.field(fieldName).getData().OnData.bind(
function(){
// do stuff - "this" refers to the OnData object
aCopyOfTheVariableIWantToFill = ...
}
);
Basically, within the bind function "this" refers to OnData and not the scope of the parent. But, by creating a local variable with the "var" keyword (aCopyOfTheVariableIWantToFill) I can get calculations out of the bind function and into the parent object. The this.theVariableIWantToFill is filled. If I used "let" instead of "var" it wouldn't work.
