Skip to Content
avatar image
Former Member

Problem with eventhandler and this

Hi

I got a problem with "this" in an eventhandler, when i create a new entity using the odata.v2 model.

I wan´t to call a method on another controller, when the update is successful.

oModel.create('/data', oEntry, {success: this._oListController.createOk});

The this._oListController.createOk method is called, but in the method "this" point to the window object. How can i change the reference to another type?

Kind regards,

Kim

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Oct 26, 2015 at 07:36 AM

    oModel.create('/data', oEntry, {success: $.proxy(this._oListController.createOk, this._oListController.) } );

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 25, 2015 at 07:48 PM

    Hi Kim

    Have you try this?

    {success: [this._oListController.createOk, this._oListController]}

    Thanks

    -D

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 26, 2015 at 07:29 AM

    Hi Kim,

    Did you try like this as well?

    var that = this._oListController;
    oModel.create('/data', oEntry, {success: function(){
      that.createOk;
      }});
    

    Regards,

    Sai Vellanki.

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 26, 2015 at 07:49 AM

    https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_objects/Function/bind

    There are many ways to do it. Adding to the answers above, you can make use of javascript's bind method to pass *this* context to the function.

    {success:this._oListController.createOk.bind(this)};
    
    Add comment
    10|10000 characters needed characters exceeded