2018 Apr 05 9:44 PM - edited 2024 Feb 04 3:48 AM
Hi,
This is basic but I am new to javascript so appreciate any help.
My controller, View1.controller.js., has two functions. onSLConnect is being called from a button press and is working correcty.
However, the call to onConnectSuccess does not seem to execute. The label text does change.
Is it possible to call functions that are in the same javascript file? Is there something I need to do to enable that?
Or do I need to put the called function in its own file?
onConnectSuccess(thisView) {
var oLabel1 = thisView.byId("Label1");
oLabel1.setText("Success");
},
onSLConnect: function() {
var thisView = this.getView();
.........
this.onConnectSuccess(thisView);
}
Thanks,
Mel
Request clarification before answering.
The problem was that the function I created was part of the controller and not the view.
I was trying to call the code from inside a "press" event so the function had to be referenced explicitly to the controller:
The function was created in the ...controller.js
onLoginSuccess : function(thisView){.......}
As was the calling function - which fails.
onSLConnect: function() {
//.............(code that works)
var thisView = this.getView();
this.onLoginSuccess(thisView); ---Fails
Answer:
var thisView = this.getView();
var oController = sap.ui.controller("MyAppMyApp.controller.View1"); ---the reference is in the first line of the ....controller.js
oController.onLoginSuccess(thisView);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
onConnectSuccess:function(thisView) {
var oLabel1 = thisView.byId("Label1");
oLabel1.setText("Success");
},
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jun,
Thanks for your response but I am still having a problem.
This is from my actual code in the controller.
onSLConnect definitely executes but oLabel1 does not get set to "Success."
onLoginSuccess: function(thisView) {
var oLabel1 = thisView.byId("Label1");
oLabel1.setText("Success");
},
onSLConnect: function() {
//.............(code that works)
var thisView = this.getView();
this.onLoginSuccess(thisView);
}
are you using js view?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jun,
I am using an xml view with a js controller. Is that what you mean?
The controller exposes functions such as my
onSLConnect. This executes when the button is pressed.
Now I would like to call my other function
this.onConnectSuccess which is in the same js controller file.
There are no errors but the code does not seem to run.
| User | Count |
|---|---|
| 29 | |
| 14 | |
| 14 | |
| 6 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 3 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.