on 07-30-2016 10:42 PM
Hi All,
I need to make some changes to the standard app. I have extended the controller to implement the custom logic. how to call the parent function from the extended controller?
Ex: in S1.Controller.js I have a function senddata and checkdata(). I have extended the controller as S1Custom.Controller.js. In the senddata method i have to perform some additional validations but Can I use the checkdata() function from the parent?
Thanks
Gopi
you used sap.ui.define and Controller.extend ("Custom.Controller", ...) ?
actually, if you did not "re-define" checkdata method in Custom.Controller (to override the base's logic) ... you can just use this.checkdata() too. Javascript will search up the prototype chain and execute from the parent if it finds the method there.
or you can explicitly call the method by referring to the parent's prototype like below:-
Controller.prototype.checkdata.call(this); // you can pass arguments too
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please mark this Discussion with a Correct Answer (closes, but does not lock the Discussion) and Helpful Answer where appropriate. See http://scn.sap.com/community/support/blog/2013/04/03/how-to-close-a-discussion-and-why Even if you discovered the solution without any outside contributions, it helps others to understand what the solution turned out to be.
Do not use Assumed Answered as it confuses anyone looking for the specific answer. If you dig into the Getting Started link (top right of each SCN page), you are only instructed to mark Helpful or Correct Answers to Discussion responses.
Thanks, Mike (Moderator)
SAP Technology RIG
Hi,
Here's the solution.
A Confirmation dialog was raised from the S1Custom.Controller.js. When User Click Accept button, I need to call a method checkData(). But when I used this.checkData(), it was throwing an error.
So before the Dialog was raised I copied the reference from this to that.
ex: var that = this; and called the that.checkData();
Thanks
Gopi
thanks for the update and glad things are working now.
anyhow, for the sake of clarity and completeness - for others reading (who may not be familiar with Javascript) - the root cause of what you have shared in the latest post is different from your initial question at the start of this thread.
essentially it was a scope issue with "this". because you were expecting "this" to be the Custom Controller but instead it was the Dialog's
this.checkData() would have worked if "this" was the Custom Controller. few ways that this will be the case:-
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.