on 07-26-2018 11:11 AM
Hello,
I want to call a function inside a dialog after pressing on a button: It looks like this:
example: function(oEvent){
console.log("a");
},
var dialog = new Dialog({
title: 'Title',
type: 'Message',
content: [new Label({
text: 'Parameter 1:', labelFor: 'labelforparameter1'}),
new TextArea('labelforparameter1', {
width: '50%',
height: '50%',
placeholder: 'fill out'})],
beginButton: new Button({
text: 'Download',
icon: 'sap-icon://download',
press: function () {
this.example(oEvent); //Thats where I want to } call a function
});
dialog.open();
}
But i always get the Error Message this.example is not a function.
Both functions are defined in the same controller.
How do I solve this problem?
thanks.
the "this" keyword refers to the event since it is inside of the press event. you should put the function in the controller... then following MVC practices you could call it as: yourController.example ... otherwise, you need to do something like:
var self = this; // at the view level...
then in the press event... call it as: self.example that way you are using the right scope
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
add .bind(this) to your press function.
beginButton: new Button({
text: 'Download',
icon: 'sap-icon://download',
press: function () {
this.example(oEvent);
}.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,
Define var that = this within function & Use that instead of this in press function like below Code
beginButton: new sap.m.Button({ text: "Save", press: function() { that.saveAction(); dialog.close(); } }),
Otherwise you can use Below method also;
var that = this;
press:[that.example,that];
-----------------
example:function(oEvent){
----------------
}
Regards,
asha
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kerem Ünal,
try this code. i did change
you have to call function like this
press: this.onDialogBegin.bind(this)
onDialogBegin: function(oEvent) {
console.log("a");
},
fnCreatDialog: function() {
var dialog = new sap.m.Dialog({
title: 'Title',
type: 'Message',
content: [new sap.m.Label({
text: 'Parameter 1:',
labelFor: 'labelforparameter1'
}),
new sap.m.TextArea('labelforparameter1', {
width: '50%',
height: '50%',
placeholder: 'fill out'
})
],
beginButton: new sap.m.Button({
text: 'Download',
icon: 'sap-icon://download',
press: this.onDialogBegin.bind(this) //Thats where I want to } call a function
})
});
dialog.open();
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just put, press: 'onDialogBegin'. This function shall be defined in the controller as separate method.
Meanwhile, try to assign functions for beforeOpen, beforeClose etc. events for the Dialog, if you want to handle them too.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thank you for your answer.
Do you mean like this?
onDialogBegin: function(oEvent){
console.log("a");
},
var dialog = new Dialog({
title: 'Title',
type: 'Message',
content: [new Label({
text: 'Parameter 1:', labelFor: 'labelforparameter1'}),
new TextArea('labelforparameter1', {
width: '50%',
height: '50%',
placeholder: 'fill out'})],
beginButton: new Button({
text: 'Download',
icon: 'sap-icon://download',
press: 'onDialogBegin' //Thats where I want to } call a function
});
dialog.open();
}
If yes, unfortunately it still doesnt work. I now get the error message 'I.fFunction.call is not a function'. And if i change it to press: this.onDialogBegin(oEvent); i get the same error message as before: this.onDialogBegin is not a function.
beginButton: new Button({
text: 'Download',
icon: 'sap-icon://download',
press: this.example
});
Try it like this
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.