• If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Announcement

Collapse
No announcement yet.

The dreaded scope question...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • The dreaded scope question...

    Hi Guys. Just when I thought I finally had a handle on this scope stuff this event shows me I do not. The code snippet below is in a controller. Note that the reference to FPEOrderWindow is valid (works) in the Success function of getUnitByTag function. It then calls function moveUnit to process the data it got back from server. But in that function, it can not reference FPEOrderWindow, shows undefined in console.log. What is proper technique to fix this?

    Code:
     getUnitByTag : function() {      
    
    Ext.Ajax.request({        
    url: '/valence/vvcall.pgm',        
    scope: this,        
    params: {            
          pgm: 'VALV450',
           action: 'getByTag',
            tagno: this.getFPEOrderWindow().down('#NEWTAG').getValue(),            
          order: this.getFPEOrderWindow().down('#FEORDER').getValue(),
           operno: this.getFPEOrderWindow().down('#FEOPER').getValue(),
          },        
    success: function (response) {            
         var check = response.responseText;
           if (check) {                
             var data = Ext.decode(response.responseText);                
             if (data.SUCCESS === '1') {
                        this.moveUnit(data); 
                         this.getFPEOrderWindow().down('#NEWTAG').setValue('');  
      } else {  
            Ext.Msg.alert('Error-', data.MSG);  
       }
                } else {                
    Ext.Msg.alert('Received a null response from the server when attempting to get by tag.');             }        
    },        
    failure: function () {            
          Ext.Msg.alert('Received a failure response from the server when attempting to get by tag.');        
    }    
    }) },  
    
    moveUnit : function(data) {  
          console.log(this.getFPEOrderWindow().down('#FEINORD1').getValue());
    Last edited by TerryB; 04-22-2019, 01:28 PM.

  • #2
    Wow, those code tags do not like formatting done by tab key. Now I see why WebStorm always asking why I'm doing that. I used edit to clean up code best I could.

    Comment


    • #3
      Well, maybe I understand scope better than I thought. Something else is going on here. When I console log the form itemId #NEWTAG instead of #FEINORD1, It works without an undefined error, shows the value. But FEINORD1 is a valid itemId, it is used all over the place in other functions in the controller. I'll keep experimenting but let me know if you think you know what is going on here. This makes no sense to me right now. I thought it just had no ref to the Window object, it obviously does.

      Comment


      • #4
        Nothing is standing out to me, but I would refactor the code a bit to be like this:

        Code:
        
        getUnitByTag : function (){
           var me        = this,
               fpeOrdWdw = me.getFEPOrderWindow();
        
           Ext.Ajax.request({
               url : '/valence/vvcall.pgm',
               scope : me,
               params : {
                   pgm : 'VALV450',
                   action : 'getByTag',
                   tagno : fpeOrdWdw.down('#NEWTAG').getValue(),
                   order : fpeOrdWdw.down('#FEORDER').getValue(),
                   operno : fpeOrdWdw.down('#FEOPER').getValue(),
               },
               success : function (response){
                   var data = Ext.decode(response.responseText);
                   if (data.SUCCESS === '1'){
                       me.moveUnit(data);
                       fpeOrdWdw.down('#NEWTAG').setValue('');
        
                   } else{
                       Ext.Msg.alert('Error-', data.MSG);
                   }
               },
               failure : function (){
                   Ext.Msg.alert('Received a failure response from the server...');
               }
           })
        },

        Comment


        • #5
          Thanks Sean. I'm starting to understand why a lot of code assigns me = this. It does clear up some confusion in situations like this. But I found issue, it had nothing to do with scope. The fieldset that contains FEINORD1 is initially hidden until it is used, that is at the heart of my problem. So it likely was undefined, it had not been rendered yet. My concern was I had no reference to the panel to examine it's items, that is not the case.

          I had not tried this technique of calling a function from the Success function (I have 100+ lines of code to do stuff with the returned data), I was wondering if maybe this function had no access to the objects the controller has defined references to. That is not my problem.

          Sorry to bother you, should have dug a little deeper first like I have been now.

          Comment

          Working...
          X