ExtJS: Passing Parameter in Function Handler

July 31st, 2010 by aditia rahman / 1 Comment  

     

This is a very short post in my ExtJS posts, when we dealing with handler config in many component sometimes we want to passing the parameter inside the function, so here the simple code on how I do it

Ext.onReady(function() {
    var myHandler = function (name){
       Ext.Msg.alert('Notification', 'Hello ' + name);
    };

    var form = new Ext.FormPanel({
        frame: true, border: false, buttonAlign: 'center',
        url: 'test.php', method: 'POST',
        buttons: [{
            text: 'Submit Test',
            handler: myHandler.createDelegate(this, ['Luffy'])
        }]
    });

    var winLogin = new Ext.Window({
        title: 'Function Handler Parameter',
        layout: 'fit', width: 200,
        height: 80, resizable: false,
        border: false,
        closable: false, items: [form]
    });
    winLogin.show();
});

You can see above the code have just have to add the createDelegate method in the function, the ‘Luffy’ is the parameter that we passed through the function and remember to declare function first before the function is called, otherwise the script won’t run well.

        submit to reddit Delicious

Others You May Like

One Comment Leave a Comment Subscribe RSS

Leave a Comment

You must be logged in to post a comment.