【发布时间】:2021-08-31 15:25:36
【问题描述】:
我有一个包含日期字段和时间字段元素的表单。我将日期字段格式编辑为 Y-m-d 和时间输出如下:
var form = Ext.getCmp('travelForm').getForm();
var record = form.getRecord();
var values = form.getValues();
if (values.hora_inicio!='')
values.hora_inicio = values.hora_inicio + ':00';
if (values.hora_termino!='')
values.hora_termino = values.hora_termino + ':00';
if (values.hora_ingreso!='')
values.hora_ingreso = values.hora_ingreso + ':00';
record.beginEdit();
record.set(values);
record.endEdit();
console.log(JSON.stringify(values));
JSON.stringify(values) 的显示是我的格式正确的数据,但是当我这样做时
record.save()
它失败了,因为请求负载表明提到的数据(时间字段和日期字段值)是 ISO 日期('YYYY-mm-dd'T'HH:MM:SS)。我猜这与时间字段和日期字段元素作为对象的输出有关,但我需要了解如何更改记录的格式以使用正确的输出执行 record.save()。
编辑
按照建议,我包括时间字段和日期字段的配置。它们是我表单的“项目”配置的一部分:
{
xtype: 'datefield',
margin: '5 0 0 0',
labelWidth: 150,
labelSeparator: ' ',
submitEmptyText: false,
anchor: '100%',
format:'Y-m-d',
fieldLabel: 'Fecha Inicio',
emptyText: 'Fecha Inicio',
name:'fecha_inicio',
allowBlank: false,
},
{
xtype: 'timefield',
minValue: '0:00',
maxValue: '23:30',
format: 'H:i',
increment: 30,
anchor: '100%',
fieldLabel: 'Hora Inicio',
id: 'form_hora_inicio',
emptyText: 'Hora Inicio',
name:'hora_inicio',
allowBlank: false
},
这个模型是:
Ext.define('Admin.model.travel.Travel', {
extend: 'Admin.model.Base',
fields: [
{
name: 'nombre'
},
{
name: 'fecha_inicio',
type: 'string'
},
{
name: 'hora_inicio',
type: 'string'
},
{
name: 'fecha_termino',
type: 'string'
},
{
name: 'hora_termino',
type: 'string'
}
],
idProperty: 'id_travel',
proxy: {
type: 'ajax',
reader: {
type: 'json',
rootProperty: 'data'
},
api: {
create : 'index.php/travel/create_travel',
//read : '',
update : 'index.php/travel/update_travel',
destroy : 'index.php/travel/delete_travel'
}
}
});
如果我这样做,我也可以指出这一点
console.log(record.data)
它显示了 2 个显示:首先,数据为 JSON,格式正确,然后再次显示数据,但所有日期都转换为 ISO 格式。
【问题讨论】:
-
请您提供您的记录(模型)定义。时间和日期表单字段配置..或一些小提琴示例?
-
@ArthurRubens 完成。我不确定我的记录定义是什么;我还是 ExtJs 的新手。
-
record.save()
-
据我了解,它是默认定义的,因为项目使用 CodeIgniter
-
CodeIgniter 是 BE 的一部分。在您的 FE 中必须是表格使用的记录的定义。这条记录必须有一些代理配置..
标签: javascript extjs datefield extjs6.2 timefield