javascriptsapui5

How to bind SAP UI5 Model response with the handler function


I have a function which creates an entry in backend when the 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 bound the _onSuccess function to oModel.create 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 how to 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)
  });
},

Solution

  • Just keep the parameters same as directly include function.

    _onSuccess: function (data, response) {
    
    }