on 03-14-2021 5:58 AM
Hi All,
I am trying to access controller object inside OData Read Success function.
I am trying to use var that = this; But somehow this is not working.
Can anyone help me to resolve this. my UI5 library version is 1.38.1.
Thanks,
Vengadesh R
u need to access it first inside, then only in the debugger you can access "that". But you don't need to do that old approach, try doing like below, yyou can access "this" directly in the success handler.
model.read("...",
success:{
...
}.bind(this) // This will pass the "this" reference of the called function inside the success handler
)
Mahesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
vengadesh.r It's the same anywhere..
https://ui5.sap.com/#/api/sap.ui.model.odata.v2.ODataModel%23methods/attachBatchRequestCompleted
attachBatchRequestCompleted(... , function(){}.bind(this))
but as per the documentation, they are passing oListner, which means the context object to the event handler. So maybe try like below as well.
attachBatchRequestCompleted(... , function(){}, this)
Regards,
Mahesh
vengadesh.r There is a gotcha about passing an anonymous function directly: it cannot be detached. Better pass a function reference and the listener.
attachBatchRequestCompleted(this.onBatchRequestCompleted, this);
This will make sure that the handler can be also detached once it's no longer required. See https://stackoverflow.com/a/62120803/5846045.
Thank you Mahesh , You are a Champ !!
Same issue as https://answers.sap.com/questions/13194201/. In the debugger environment, closure variables cannot be accessed within a function due to how the V8 (JS engine in Chromium) optimizes JS in the runtime.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.