0

我有一个包含日期字段和时间字段元素的表单。我将日期字段格式编辑为 Ymd 和时间输出,如下所示:

    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 格式。

4

1 回答 1

0

如果它对任何人有用,就在之前

record.save();

有一个

form.updateRecord(record);

这导致从表单中再次检索对象“记录”的值,并出现各种格式问题。评论这对我有用。

于 2021-06-16T01:19:35.663 回答