Javascript 在函数extjs之间传递var
我有一个大问题,我需要在我的程序中,在两个函数之间传递一个字段的值以进行计算,如果该字段的新值是允许的,我粘贴代码是因为更容易理解我假装看代码做什么:Javascript 在函数extjs之间传递var,javascript,extjs,Javascript,Extjs,我有一个大问题,我需要在我的程序中,在两个函数之间传递一个字段的值以进行计算,如果该字段的新值是允许的,我粘贴代码是因为更容易理解我假装看代码做什么: beforeedit: function preditar(editor, e, eOpts) { var grid = Ext.getCmp('gridTabla'); // or e.grid var hoy = new Date(); dia = hoy.getDa
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
});
}
}
编辑前:
函数preditar(编辑器、e、eOpts){
var grid=Ext.getCmp('gridTabla');//或e.grid
var hoy=新日期();
dia=hoy.getDate();
如果(dia将其放入函数参数中
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";
}
您只需将值存储在记录的自定义属性中:
// in beforeedit:
e.record.beforeEditESTLOT = e.record.data.ESTLOT
然后,在编辑中:
// your value's in there:
alert(e.record.beforeEditESTLOT);
现在,甚至还有一个最简单的方法。由于您的记录将由编辑器修改,因此您可以在记录的属性中找到您的值。因此,在记录保存之前(即使用模型或存储函数保存),您可以通过以下方式访问上一个值:
// if undefined, that means that the ESTLOT value has not been changed by the editrecord.modified.ESTLOT
alert(record.modified.ESTLOT);
好的,我现在粘贴,我的应用程序中验证字段值的部分取决于他以前的值。感谢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
});
}
}
}
});
var gridTablaConsulta=Ext.create('Ext.grid.GridPanel'{
标题:'Consulta Tabla lotes',
id:'GridTablea',
商店:可储存表格A,
栏目:[
Ext.create('Ext.grid.RowNumberer'),
{文本:“NRBE”,宽度:60,可排序:true,数据索引:'NRBE'},
{文本:“APLIC”,宽度:60,可排序:true,数据索引:'APLIC'},
{text:“FORM”,宽度:60,可排序:true,数据索引:'FORM'},
{文本:“VERFOR”,宽度:60,可排序:true,数据索引:'VERFOR'},
{文本:“FECLOT”,宽度:60,可排序:true,数据索引:'FECLOT'},
{文本:“HORLOT”,宽度:60,可排序:true,数据索引:'HORLOT'},
{文本:“TIPPAPLO”,宽度:60,可排序:true,数据索引:'TIPPAPLO'},
{文本:“TAMPAP”,宽度:60,可排序:true,数据索引:'TAMPAP'},
{文本:“fecinim”,宽度:60,可排序:true,数据索引:'fecinim'},
{text:'FECINIOB',width:60,sortable:true,dataIndex:'FECINIOB',编辑器:{xtype:'textfield',allowBlank:true},
{text:'ESTLOT',width:60,sortable:true,dataIndex:'ESTLOT',编辑器:{xtype:'textfield',allowBlank:true},
{文本:“TOTPAGGE”,宽度:60,可排序:true,数据索引:'TOTPAGGE'},
{文本:“TOTPAGIM”,宽度:60,可排序:true,数据索引:'TOTPAGIM'},
{文本:“DESLOT”,宽度:60,可排序:true,数据索引:'DESLOT'},
{text:“TIPDIF”,宽度:60,可排序:true,数据索引:'TIPDIF'},
{文本:“DIADIF”,宽度:60,可排序:true,数据索引:'DIADIF'},
{文本:“fealt”,宽度:60,可排序:true,数据索引:'fealt'},
{文本:“FECMOD”,宽度:60,可排序:true,数据索引:'FECMOD'},
{文本:“TERMOD”,宽度:60,可排序:true,数据索引:'TERMOD'},
{文本:“HORMOD”,宽度:60,可排序:true,数据索引:'HORMOD'}
],
selType:“行模型”,
插件:[
Ext.create('Ext.grid.plugin.RowEditing'{
单击编辑:2
})
],
听众:{
编辑前:
函数preditar(编辑器、e、eOpts){
var grid=Ext.getCmp('gridTabla');//或e.grid
var hoy=新日期();
dia=hoy.getDate();
如果(diaHi rixo)在我尝试第一个解决方案时出现下一个失败:“record.beforeEditESTLOT”为null或不是一个对象。但是如果这一切都是正确的,我认为,alert(record.modified.ESTLOT);再次感谢jejej你解决了我的问题,再次感谢jejej最后一件事是我需要抓住ESTLOT的新值(传递给servlet的值)