cancel
Showing results for 
Search instead for 
Did you mean: 

How to bind SAP UI5 Model response with the handler function

0 Kudos

I have a function which create an entry in backend when an button ( save button ) is pressed.

Code for creating entry

var oModel = this.getModel('action');
oModel.create(path, body, {
  success: this._onSuccess.bind(this),   //How to pass response along with the bind function
  error: this._onError.bind(this)
});
_onSuccess: function (response) {
  // Response is not having any headers
  //Show some success message
},

Instead of directly calling the function, I have binded the _onSuccess function to oModel.create's success handler. From the backend I am sending some header parameters along the (POST) response, which I need to access inside the _onSuccess message and display. When I directly include the function in success handler, I am able to see the response, but not sure how send it along the bind parameter

This is working

callCreate: function (path, body) {
  var oModel = this.getModel('action');
  oModel.create(path, body, {
    success: function (data, response) {
        //I am able to get the response headers here
    },
    error: this._onError.bind(this)
  });
},

 

 

 

View Entire Topic
sajid-khan
Explorer
0 Kudos

Hi, you just need to add an additional parameter to your _onSuccess function definition. Modify your _onSuccess function definition on line 6 to following:

var oModel = this.getModel('action');
oModel.create(path, body, {
  success: this._onSuccess.bind(this),   //How to pass response along with the bind function
  error: this._onError.bind(this)
});
_onSuccess: function (data, response) {
  // Response is not having any headers
  //Show some success message
},