on 07-21-2020 11:40 AM
I'm trying to set a model and retrieving it from OData after pressing a certain button.
The problem is when I call getModel outside of the "success" function, it returns undefined.
Because "onPressButton1" runs fully before the "success" function gets executed.
So is there a way to make sure "success" function is called first? and within the onPressButton1.
If I put my whole code in "success" function, I'll not be able to use "this" key word to call functions "this.fDoThis();"
Code for reference:
onPressButton1: function() {
var vEntityURL = "/CustomerSet(ID='000')";
var sServiceUrl = "/Customers_SRV/";
var oServiceModel = new sap.ui.model.odata.ODataModel(sServiceUrl, true);
var oJsonModel = new sap.ui.model.json.JSONModel();
oServiceModel.read(vEntityURL, {
success: function(oData) {
oJsonModel.setData(oData);
sap.ui.getCore().setModel(oJsonModel, "Customers");
}
});
var oCustomer = this.getView().getModel("Customers");
console.log(oCustomer.getProperty("/Name"));
}
Use V2 odata model, v1 is deprecated.
Try chanfing the success handler as shown below. Add.bind(this) and set model to view
success: function(oData) {
oJsonModel.setData(oData);
this.getView().setModel(oJsonModel, "Customers");
}.bin(this)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
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.