on 09-29-2015 3:47 PM
I guess the variables are available and have seen at times the debugger just doesn't pick the variables in the closure when it isn't used ! Try doing this,
function fnSuccess(oContext){
debugger;
console.log(oModel);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
try to flip createBindginContext call and function declaration (so it will be first)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Already tried that too.
The variables are all valid in the scope of the caller of createBindingContext:
The module this userPopover function is declared in is declared this way:
sap.ui.define([ "sap/ui/model/Filter", "sap/ui/model/json/JSONModel", "myapp/util/Formatter" ], function(Filter, JSONModel, Formatter) {
"use strict";
return {
// Definitions go here...
};
});
I wonder why in Chrome Devtool I see sap.ui.define.Formatter.userPopover in the call stack.
Could this have anything to do with this issue?
I used to do it that way too, but since the release of 1.30 I switched to the new AMD way of defining my modules because that seems the way to go for the future.
I was only asking because I would have expected to see sap.ui.define.Dialogs.userPopover in the call stack and not sap.ui.define.Formatter.userPopover because my function is in the Dialog.js module.
Tried that and the new variable is not in scope.
I tried something else:
I passed my callback function to createBindingContext because the data will be loaded asynchronously if it is not yet present in the model.
In my case I know that the data has been loaded before so I just tried to call my callback manually and passing the context returned synchronously from createBindingContext:
var oCtx = oModel.createBindingContext(sPath);
if (oCtx) {
fnSuccess(oCtx);
}
In this case all closure variables are visible in my callback function (see above).
So it must have something to do with the callback being called by the library but I don't know what it could be.
Anyway, this was just a try and I don't want to rely on the context being returned synchronously for an application in production.
What I wanted to express was that we cannot rely on the return value of createBindingContext because if the entity requested is not yet present in oModel.oData the function returns undefined and triggers the asynchronous loading of the odata entities.
So it is better to use the callback function in any case because this will always receive the context (with data already loaded). Either immediately if the data has been loaded already or asynchronously as soon as the data has been loaded from the server.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
6 | |
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.