on 11-26-2017 11:29 AM
Hi everyone!
I am trying to learn SAP UI5 myself and I have the following doubt.
If anyone could help me I would be grateful to you!
[Sorry for pasting little code here. Without showing the code I am not sure how I can explain this 😞 ]
createContent : function(oController) {
console.log("createContent() of main view called...");
var exitButton = new sap.ui.commons.Button({ id : "exitButton",
text : 'Exit and kill controller',
pess : [ function(oEvent) {
this.destroy();
alert("View and Controller destroyed..."); } , alert("Hello") ] });
mainPanel.addContent(exitButton);
return mainPanel; }
When I run this "Hello" is displayed first which means before creating the exitButton, alert("Hello") statement is executed. How does it happen?
Thanks and regards,
P
Hi Prince P,
Firstly, you should not insert your press functionality inside an array. The second alert (hello message) gets executed at beginning because of the callback functions and the SAPUI5 controller hook methods. Refer the foll. links for more information :
https://archive.sap.com/discussions/thread/3650876
Regards,
Arjun Biswas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
There is a nonsense in your code. The mistake is, the press event is not an array of function, but only one function, you put it in an array :
...
Press: [ function1, function2]
...
This is not correct. It should be :
Press: function
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Look at this Link
Dear Joseph,
I was following the same. For press event there is an array consisting of a function and 'this'. You have pointed out that press event is not array of function it is only one function. Please clarify this. Thanks and regards, P
press :[function(oEvent){
this.destroy();
alert("View and Controller destroyed...");
},this]
Thank you very much for your responses.
In the following code the value of 'this' is the view but then how does it invoke the 'onExit' of the controller?
press :[function(oEvent){
this.destroy();
alert("View and Controller destroyed...");
},this]
Also when 'this' is replaced with an alert("Hello") statement "Hello" is displayed first which means before creating the object exitButton, alert("Hello") statement is executed. How does it happen?
pess : [ function(oEvent) {
this.destroy();
alert("View and Controller destroyed..."); } , alert("Hello") ] });
Best regards,
P
Hi Prince,
It's one of the functionality of jQuery ie. Callback functions. Please check below links to understand callback functions.
http://javascriptissexy.com/understand-javascript-callback-functions-and-use-them/
https://www.w3schools.com/jquery/jquery_callback.asp
Hope this will clear your doubts.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Irfan,
Thank you for your reply.
Is there any way to create the exitButton first then display alert("Hello")?
"press" member of the function(constructor) 'sap.ui.commons.Button' is an array of 2 items which are 1. function(oEvent) and 2. alert("Hello")
Also there is no effects to take place for the delay to execute alert("Hello")
I have gone through the links which you have provided and understand what callback function is however I am not able to understand this scenario. If you can explain bit it will be a great help.
Best regards,
P
User | Count |
---|---|
95 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.