1. #1
    Sencha User
    Join Date
    Mar 2009
    Posts
    356
    Vote Rating
    0
    Answers
    1
    koko2589 is on a distinguished road

      0  

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

    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,616
    Vote Rating
    327
    Answers
    545
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      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
    Vote Rating
    0
    Answers
    1
    koko2589 is on a distinguished road

      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
    ycuk is on a distinguished road

      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
    Vote Rating
    0
    Answers
    1
    koko2589 is on a distinguished road

      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
    Vote Rating
    0
    Answers
    1
    koko2589 is on a distinguished road

      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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,525
    Vote Rating
    872
    Answers
    3564
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      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 @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.