在函数EXT js之间传递var

时间:2013-06-18 20:50:03

标签: javascript extjs

我有一个很大的问题,我需要在我的程序中传递两个函数之间的字段值来评估该字段的新值是否允许,我粘贴代码因为更容易理解我假装做的看代码:

   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
         });
     }
    }

Mi最大的问题是我想在编辑函数editar(context,e)之前传递ESTLOT字段表单的值,而且我不知道我该怎么做。

有人可以帮我传递var ESTLOT,它是我对编辑函数优先考虑的字段的值吗?

由于

3 个答案:

答案 0 :(得分:1)

您只需将值存储在记录中的自定义属性中:

// in beforeedit:
e.record.beforeEditESTLOT = e.record.data.ESTLOT

然后,在编辑中:

// your value's in there:
alert(e.record.beforeEditESTLOT);

现在,甚至有一种最简单的方法。由于您的记录将由编辑器修改,您可以在记录的modified属性中找到您的值。因此,在记录为commited之前(即使用模型或商店功能保存),您可以通过这种方式访问​​上一个值:

// if undefined, that means that the ESTLOT value has not been changed by the editrecord.modified.ESTLOT
alert(record.modified.ESTLOT);

答案 1 :(得分:0)

将它放在函数参数

function editar(e, context, ESTLOT)
{
  //....rest of your operation
}

参考GlobalVAR

 Var ESTLOT;

 function editar(e, context)
 {
   //....rest of your functions 
  ESTLOT = "abcd";
 }
 function preditar(editor, e, eOpts) 
 {
  ESTLOT = "abcd";
 }

答案 2 :(得分:0)

好的,我现在粘贴,我的应用程序中我验证字段值的部分取决于他以前的值。感谢Rixo和Jono的帮助。

            var gridTablaConsulta = Ext.create('Ext.grid.GridPanel', {
    title:'Consulta Tabla lotes',
    id:'gridTabla',
    store: storeTabla,
    columns: [
        Ext.create('Ext.grid.RowNumberer'),
        {text: "NRBE", width: 60, sortable: true, dataIndex: 'NRBE'},
        {text: "APLIC", width: 60, sortable: true, dataIndex: 'APLIC'},
        {text: "FORM", width: 60, sortable: true, dataIndex: 'FORM'},
        {text: "VERFOR", width: 60, sortable: true, dataIndex: 'VERFOR'},
        {text: "FECLOT", width: 60, sortable: true, dataIndex: 'FECLOT'},
        {text: "HORLOT", width: 60, sortable: true, dataIndex: 'HORLOT'},
        {text: "TIPPAPLO", width: 60, sortable: true, dataIndex: 'TIPPAPLO'},
        {text: "TAMPAP", width: 60, sortable: true, dataIndex: 'TAMPAP'},
        {text: "FECINIIM", width: 60, sortable: true, dataIndex: 'FECINIIM'},
        {text: "FECINIOB", width: 60, sortable: true, dataIndex: 'FECINIOB',editor:{xtype:'textfield', allowBlank:true}},
        {text: "ESTLOT", width: 60, sortable: true, dataIndex:'ESTLOT',editor:{xtype:'textfield', allowBlank:true}},
        {text: "TOTPAGGE", width: 60, sortable: true, dataIndex: 'TOTPAGGE'},
        {text: "TOTPAGIM", width: 60, sortable: true, dataIndex: 'TOTPAGIM'},
        {text: "DESLOT", width: 60, sortable: true, dataIndex: 'DESLOT'},
        {text: "TIPDIF", width: 60, sortable: true, dataIndex: 'TIPDIF'},
        {text: "DIADIF", width: 60, sortable: true, dataIndex: 'DIADIF'},
        {text: "FECALT", width: 60, sortable: true, dataIndex: 'FECALT'},
        {text: "FECMOD", width: 60, sortable: true, dataIndex: 'FECMOD'},
        {text: "TERMOD", width: 60, sortable: true, dataIndex: 'TERMOD'},
        {text: "HORMOD", width: 60, sortable: true, dataIndex: 'HORMOD'}
    ],
    selType: 'rowmodel',
    plugins: [
        Ext.create('Ext.grid.plugin.RowEditing', {
            clicksToEdit: 2
        })
    ],

    listeners: {

        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);
            e.record.beforeEditESTLOT = e.record.data.ESTLOT;
            if (e.record.data.ESTLOT === '02') {
                if (e.record.data.FECMOD === fecha_actual)
                 {
                    e.cancel = false; //permite probar mañana con cambio fecha
                 }
                else{
                    e.cancel = true; //no permite
                }

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

        },

         edit:
             function editar(e, context){
             var record = context.record;
             var recordData = record.getData();
             recordData.Funcionalidad = 'Modificar';
             var modificado = record.modified.ESTLOT; //valores anteriores
             alert(modificado);
             //var nuevo = recordData.ESTLOT;
             var cadena = JSON.stringify(recordData);
             alert(cadena);
             var prueba = context.record.data.ESTLOT;//valores nuevos
             alert(prueba);
             if ((modificado==='06')||(modificado==='03'))
             {

                 if ((prueba==='01')||(prueba==='02')||(prueba==='03')||(prueba==='06'))
                     {
                     Ext.Ajax.request({
                         //url: 'http://localhost:8080/MyMaver/ServletTablaLotes',
                         url: 'http://lnxntf05:8080/MyMaver/ServletTablaLotes',
                         method: 'POST',
                         // merge row data with other params
                         params: recordData
                     });
                     }
                 else
                     {

                        alert("Si el valor anterior de estado de lote es 06 o 03 solo puede pasar a valer 04 o 05");

                     }   
             }
             if ((modificado==='04')||(modificado==='05'))
             {

                 if ((prueba==='02')||(prueba==='04')||(prueba==='05')||(prueba==='06'))
                     {
                     Ext.Ajax.request({
                         //url: 'http://localhost:8080/MyMaver/ServletTablaLotes',
                         url: 'http://lnxntf05:8080/MyMaver/ServletTablaLotes',
                         method: 'POST',
                         // merge row data with other params
                         params: recordData
                     });
                     }
                 else
                     {

                        alert("Si el valor anterior de estado de lote es 04 o 05 solo puede pasar a valer 01 o 03 o en blanco");

                     }   
             }

             if(modificado==='01')
                 {
                 Ext.Ajax.request({
                     //url: 'http://localhost:8080/MyMaver/ServletTablaLotes',
                     url: 'http://lnxntf05:8080/MyMaver/ServletTablaLotes',
                     method: 'POST',
                     // merge row data with other params
                     params: recordData
                 });

                 }
             if(modificado==='  ')
                 {
                 Ext.Ajax.request({
                     //url: 'http://localhost:8080/MyMaver/ServletTablaLotes',
                     url: 'http://lnxntf05:8080/MyMaver/ServletTablaLotes',
                     method: 'POST',
                     // merge row data with other params
                     params: recordData
                 });

                 }

         }
        }
});