0

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

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

我的大问题是我想在编辑之前传递 ESTLOT 字段表单的值来编辑功能编辑器(上下文,e),我不知道我该怎么做。

有人可以帮我将 var ESTLOT 传递给编辑函数吗?

谢谢

4

3 回答 3

1

您可以简单地将值存储在记录中的自定义属性中:

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

然后,在编辑中:

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

现在,甚至还有一个最简单的方法。由于您的记录将被编辑器修改,您可以在modified记录的属性中找到您的值。因此,在提交记录之前即使用模型或存储函数保存),您可以通过以下方式访问先前的值:

// if undefined, that means that the ESTLOT value has not been changed by the editrecord.modified.ESTLOT
alert(record.modified.ESTLOT);
于 2013-06-18T21:10:16.850 回答
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";
 }
于 2013-06-18T21:00:37.420 回答
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
                 });

                 }

         }
        }
});
于 2013-06-19T08:08:45.387 回答