1. #1
    Ext User
    Join Date
    Aug 2009
    Posts
    5
    Vote Rating
    0
    febus is on a distinguished road

      0  

    Default Ext.get call

    Ext.get call


    What is the difference if I call Ext.get method from a javascript function and from anonymous function?
    In case of anonymous function in the example below, Ext.get returns the value and myDiv1 is not null. In case of a function OnReadyHandler Ext.get returns null.
    Can you explain me why Ext.get is not working in OnReadyHandler?

    HTML Code:
    <html>
    <head>
        <title>Getting started</title>
    
    
        <link rel="stylesheet" type="text/css" 
            href="lib/extjs/resources/css/ext-all.css" />
        <script src="lib/extjs/adapter/ext/ext-base.js" ></script>
        <script src="lib/extjs/ext-all-debug.js" ></script>
        <script>
            // Function doesn't work! => myDiv1 is null!
            //function OnReadyHandler()
            //{
            //    var myDiv1 = Ext.get('div1'); // <<< NOT WORKING!
            //    myDiv1.setHeight(200);
            //}
            //Ext.onReady(OnReadyHandler());
            
            Ext.onReady(function(){
                var myDiv1 = Ext.get('div1'); //OK, myDiv1 has a value
                myDiv1.setHeight(200);
            });
            
        </script>
    </head>
    <body>
        <style type="text/css">
            .myDiv {
                border : 1px solid #AAAAAA;
                width : 200px;
                height : 35px;
                cursor : pointer;
                padding : 2px 2px 2px 2px;
                margin : 2px 2px 2px 2px;
            }
        </style>
        <div id='div1' class='myDiv'> </div>
    </body>
    </html>

  2. #2
    Sencha User carol.ext's Avatar
    Join Date
    Jun 2007
    Location
    Littleton, Colorado, USA
    Posts
    698
    Vote Rating
    28
    carol.ext has a spectacular aura about carol.ext has a spectacular aura about

      0  

    Default


    Remove the parens '()', you are calling OnReadyHandler and passing the result to Ext.onReady().

    This passes result of OnReadyHandler function call :

    Code:
    Ext.onReady(OnReadyHandler());

    This passes reference to function :

    Code:
    Ext.onReady(OnReadyHandler);

  3. #3
    Ext User
    Join Date
    Aug 2009
    Posts
    5
    Vote Rating
    0
    febus is on a distinguished road

      0  

    Default



Thread Participants: 1