on 10-15-2015 8:27 AM
Hi everyone. The following works:
var oDialog = new sap.ui.commons.Dialog();
oDialog.setTitle(sName);
oButton = new sap.ui.commons.Button();
oButton.setText("Close");
oButton.attachPress(HandleButtonClick);
oDialog.addButton(oButton);
// Open Dialog
oDialog.open();
function HandleButtonClick()
{ oDialog.close(); }
But this doesn't work when I pass the reference of oDialog
var oDialog = new sap.ui.commons.Dialog();
oDialog.setTitle(sName);
oButton = new sap.ui.commons.Button();
oButton.setText("Close");
oButton.attachPress(HandleButtonClick(oDialog));
oDialog.addButton(oButton);
// Open Dialog
oDialog.open();
function HandleButtonClick(oDialog)
{ oDialog.close(); }
Basically, to write generic functions.
You can pass the dialog instance as a next parameter after the event listener. In the event listener, you can access the dialog instance referring to *this*.
oButton.attachPress(HandleButtonClick , oDialog );
function HandleButtonClick(){
this.close(); // this -> oDialog
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your help. Just for the sake of curiosity, what would the syntax be if we were to pass two variables to the function? Or are we supposed to pass an array object?
oButton.attachPress(HandleButtonClick , oDialog1, oDialog2 );
function HandleButtonClick()
{
this.close(); // this -> oDialog // What would the syntax be???
}
Thanks again guys.
attachPress event doesn't allow multiple parameters to be passed. But You can wrap all your parameters into a single Object and pass it.
oButton.attachPress(HandleButtonClick , {param1:oDialog1, param2:oDialog2});
function HandleButtonClick(){
console.log(this.param1) // would refer to the oDialog1
}
Hi Jibran,
Wil this help...? JS Bin - Collaborative JavaScript Debugging
attachPress - is an event - you can invoke method here.
But If you want to pass argument, you should make a function call in attachPress event
Thanks,
Karthik A
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
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.