Results 1 to 7 of 7

Thread: Ext.get("link").on('click', function() { ##need help

  1. #1
    Sencha User
    Join Date
    Mar 2009
    Posts
    356
    Answers
    1
    Vote Rating
    0
      0  

    Exclamation Answered: Ext.get("link").on('click', function() { ##need help

    when i click more 1 time its open win more and more
    iwant it to open just 1 time
    tankou
    Code:
     Ext.onReady(function() {
    Ext.get("link").on('click', function() {
    var win = new Ext.Window({
       width:200,y:'20', x:'70', border:false, 
     height: 450,closeAction: 'hide'
     
      }); win.show();
             });
     
     
    
        });
    my ext js site
    http://www.itoto4.com/

  2. First, let's clean your original code up so we can all easily read it:

    Code:
    Ext.onReady(function() {
        Ext.get('link').on('click', function() {
            var win = new Ext.Window({
                width       : 200,
                y           : 20,
                x           : 70,
                border      : false, 
                height      : 450,
                closeAction : 'hide'
            });
            win.show();
        });
    });
    Now, if you want a listener to fire only once and remove itself, you can use the single listener config (changes in red):

    Code:
    Ext.onReady(function() {
        Ext.get("link").on('click', function() {
            var win = new Ext.Window({
                width       : 200,
                y           : 20,
                x           : 70,
                border      : false, 
                height      : 450,
                closeAction : 'hide'
            });
            win.show();
        }, null, { single : true });
    });
    Problem is, when a Window is closed, that link is no longer going to fire the click event. The way to get around that is not to use the single config and since you are using closeAction as 'hide', just need to see if there is already a Window:

    Code:
    Ext.onReady(function() {
        var win;
        Ext.get('link').on('click', function() {
            if (!win) {
                //if there is no Window, create one!
                win = new Ext.Window({
                    width       : 200,
                    y           : 20,
                    x           : 70,
                    border      : false,
                    height      : 450,
                    closeAction : 'hide'
                });
            }
    
            win.show();
        });
    });

  3. #2
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,790
    Answers
    583
    Vote Rating
    391
      0  

    Default

    When you say open one time...

    Do you mean that you want the window to open only when the user clicks the element the first time?

    Or do you mean that you only want the window to show if it isn't already showing?

  4. #3
    Sencha User
    Join Date
    Mar 2009
    Posts
    356
    Answers
    1
    Vote Rating
    0
      0  

    Default

    if i click on the link 5 time ,to close it i need 5 time to click on close its open 5 window
    i want just 1 window to show
    tankyou
    my ext js site
    http://www.itoto4.com/

  5. #4
    Sencha User ycuk's Avatar
    Join Date
    Sep 2011
    Posts
    7
    Vote Rating
    0
      0  

    Default

    PHP Code:
     Ext.onReady(function() { Ext.get("link").on('click', function() { var win = new Ext.Window({    width:200,y:'20'x:'720'border:false,   height450,closeAction'hide',

     
    listeners: {
       
    hide: function() {
          
    Ext.get("link").un('click');
       }
     }

      }); 
    win.show();          }); 
    Approximately so

  6. #5
    Sencha User
    Join Date
    Mar 2009
    Posts
    356
    Answers
    1
    Vote Rating
    0
      0  

    Default

    Quote Originally Posted by ycuk View Post
    PHP Code:
     Ext.onReady(function() { Ext.get("link").on('click', function() { var win = new Ext.Window({    width:200,y:'20'x:'720'border:false,   height450,closeAction'hide',

     
    listeners: {
       
    hide: function() {
          
    Ext.get("link").un('click');
       }
     }

      }); 
    win.show();          }); 
    Approximately so
    no good
    i want if i clik on link 10 time to show 1 time not 10 time
    my ext js site
    http://www.itoto4.com/

  7. #6
    Sencha User
    Join Date
    Mar 2009
    Posts
    356
    Answers
    1
    Vote Rating
    0
      0  

    Default

    i want like this
    i i click 10 times its open 1 win not 10 window
    tankyou
    Code:
    Ext.onReady(function(){
     
      var win;
        var button = Ext.get('show-btn');
     button.on('click', function(){
            // create the window on the first click and reuse on subsequent clicks
            if(!win){
       
                win = new Ext.Window({
                   
                    layout      : 'fit',
                    width       : 500,
                    height      : 300,
                    closeAction :'hide',
                    plain       : true
                   
                               });}
            
            win.show(   button);
        });
    
    });
    my ext js site
    http://www.itoto4.com/

  8. #7
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,551
    Answers
    3931
    Vote Rating
    1271
      0  

    Default

    First, let's clean your original code up so we can all easily read it:

    Code:
    Ext.onReady(function() {
        Ext.get('link').on('click', function() {
            var win = new Ext.Window({
                width       : 200,
                y           : 20,
                x           : 70,
                border      : false, 
                height      : 450,
                closeAction : 'hide'
            });
            win.show();
        });
    });
    Now, if you want a listener to fire only once and remove itself, you can use the single listener config (changes in red):

    Code:
    Ext.onReady(function() {
        Ext.get("link").on('click', function() {
            var win = new Ext.Window({
                width       : 200,
                y           : 20,
                x           : 70,
                border      : false, 
                height      : 450,
                closeAction : 'hide'
            });
            win.show();
        }, null, { single : true });
    });
    Problem is, when a Window is closed, that link is no longer going to fire the click event. The way to get around that is not to use the single config and since you are using closeAction as 'hide', just need to see if there is already a Window:

    Code:
    Ext.onReady(function() {
        var win;
        Ext.get('link').on('click', function() {
            if (!win) {
                //if there is no Window, create one!
                win = new Ext.Window({
                    width       : 200,
                    y           : 20,
                    x           : 70,
                    border      : false,
                    height      : 450,
                    closeAction : 'hide'
                });
            }
    
            win.show();
        });
    });
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •