Skip to Content
0

Problem calling function in javascript

Apr 05 at 08:44 PM

285

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Mel Dodd Apr 09 at 07:28 PM
0

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);

Share
10 |10000 characters needed characters left characters exceeded
Jun Wu Apr 05 at 10:22 PM
0

are you using js view?

Show 1 Share
10 |10000 characters needed characters left characters exceeded

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.

0
Jun Wu Apr 06 at 12:51 AM
0


onConnectSuccess:function(thisView) {

var oLabel1 = thisView.byId("Label1");

oLabel1.setText("Success");

},

Show 3 Share
10 |10000 characters needed characters left characters exceeded

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);

}

0

what is this?

0

cann't u debug?

0