on 10-25-2015 6:40 PM
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
oModel.create('/data', oEntry, {success: $.proxy(this._oListController.createOk, this._oListController.) } );
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)};
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kim,
Did you try like this as well?
var that = this._oListController;
oModel.create('/data', oEntry, {success: function(){
that.createOk;
}});
Regards,
Sai Vellanki.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kim
Have you try this?
{success: [this._oListController.createOk, this._oListController]}
Thanks
-D
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.