2013-06-18 150 views
2

我有一個傢伙,我想在兩個函數之間傳遞一個變量......我該如何做到這一點?JS通過函數之間的變量

例如我的代碼是下一個

 beforeedit: 

      function preditar(editor, e, eOpts) { 
      var grid = Ext.getCmp('gridTabla'); // or e.grid 
      var hoy = new Date(); 

      dia = hoy.getDate(); 

      if(dia<10) 
       { 
        dia=String("0"+dia); 

       } 

      mes = hoy.getMonth(); 

      if(mes<10) 
      { 
        mes=String("0"+mes); 

      } 
      anio= hoy.getFullYear(); 
      fecha_actual = String(anio+""+mes+""+dia); 
      //alert(fecha_actual); 

      var mola = e.record.data.ESTLOT; 
      alert(mola); 

      if (e.record.data.ESTLOT === '02') { 
       if (e.record.data.FECMOD === fecha_actual) 
       { 
       e.cancel = false; //permite 
       } 
       else{ 
        e.cancel = true; //mo permite 
       } 

      } else 
      { 
       e.cancel = false; //permite 
      } 

     }, 

     edit: 

      function editar(e, context){ 
      var record = context.record; 
      var recordData = record.getData(); 

      recordData.Funcionalidad = 'Modificar'; 
      alert(JSON.stringify(recordData)); 


      Ext.Ajax.request({ 
       url: 'http://localhost:8080/MyMaver/ServletTablaLotes', 
       method: 'POST', 

       // merge row data with other params 
       params: recordData 
      }); 
     } 
     } 

我想了var翻車傳遞到例如編輯功能...感謝所有,我不知道我怎麼能做到這一點。 ..我沒有在互聯網上找到任何例子,我只發現將一個變量傳遞給一個函數,但不能在函數之間傳遞。

回答

4

在函數之外聲明它。 或從第一個返回它,並將其傳遞給第二個函數。

也許這樣的事情?

{ 
    mola: '', 
    beforeedit: 
    function preditar(editor, e, eOpts) { 
     var grid = Ext.getCmp('gridTabla'); // or e.grid 
     var hoy = new Date(); 

     dia = hoy.getDate(); 

     if (dia < 10) { 
      dia = String("0" + dia); 

     } 

     mes = hoy.getMonth(); 

     if (mes < 10) { 
      mes = String("0" + mes); 

     } 
     anio = hoy.getFullYear(); 
     fecha_actual = String(anio + "" + mes + "" + dia); 
     //alert(fecha_actual); 

     mola = e.record.data.ESTLOT; 
     alert(mola); 

     if (e.record.data.ESTLOT === '02') { 
      if (e.record.data.FECMOD === fecha_actual) { 
       e.cancel = false; //permite 
      } else { 
       e.cancel = true; //mo permite 
      } 

     } else { 
      e.cancel = false; //permite 
     } 

    }, 

    edit: 

    function editar(e, context) { 
     var record = context.record; 
     var recordData = record.getData(); 

     recordData.Funcionalidad = 'Modificar'; 
     alert(JSON.stringify(recordData)); 

     mola && alert(mola); 

     Ext.Ajax.request({ 
      url: 'http://localhost:8080/MyMaver/ServletTablaLotes', 
      method: 'POST', 

      // merge row data with other params 
      params: recordData 
     }); 
    } 
} 

} 
+0

難道這不僅僅是一個評論而不是回答? –

+0

我認爲這取決於代碼的上下文,以及最佳答案是什麼。 – AntouanK

+0

@harsha好,它可以擴展 –