1

我正在使用 extjs 4.1。我有一个以所需时间格式显示日期的网格。但是,当我想在窗口中显示日期、时间和超时时间以进行编辑时,只显示日期。但 intime 和 outtime 没有显示。数据库中的所有字段都是日期时间。谁能帮我解决这个问题。下面是我的代码:

我的网格如下:

Ext.define('Ext4Example.view.attendence.Datagrid' ,{
    extend: 'Ext.grid.Panel',
    alias : 'widget.datagrid',
    layout: 'fit',
    border: true,
    viewConfig: {
        stripeRows: true,
        forceFit:true,
        emptyText:'No Records to display'
    },

    hideHeaders: false,
    initComponent: function() {

        this.store = 'Attendences';
        //this.width = 400;      
        this.columns = [
        {
            text: 'Date',
            dataIndex: 'id',
            renderer: function(value, metaData){
                return Ext.Date.format(value, 'M d, Y');
            }
        },{
            text: 'Day',
            dataIndex : 'id',
            renderer: function(value, metaData){
                return Ext.Date.format(value, ' l');
            }
        },
        {
            text: 'In-Time',
            dataIndex: 'intime',
            renderer: function(value, metaData){
                return Ext.Date.format(value, 'h:i A');
            }
        },
        {
            text: 'Out-Time',
            dataIndex: 'outtime',
            renderer: function(value, metaData){
                return Ext.Date.format(value, 'h:i A');
            }
        }


        ];

        this.callParent(arguments);
    }
});

下面给出了我想要编辑值的窗口:

    Ext.define('Ext4Example.view.attendence.Editattendence' ,{
    extend: 'Ext.window.Window',
    alias : 'widget.editattendence',
    title: 'Edit Attendence',
    layout: 'fit',
    autoShow: true,
    initComponent: function () {
        this.items = [
        {
            xtype: 'form',

            bodyStyle: {
                background: 'none',
                padding: '10px',
                border: '0'
            },
            items: [
            {
                xtype: 'datefield',
                name: 'id',
                allowBlank: false,
                fieldLabel: 'Attendene ID'
            },
            {
                xtype: 'numberfield',
                name: 'intime',
                allowBlank: false,
                fieldLabel: 'IN TIME',
                renderer: function(value, metaData){
                return Ext.Date.format(value, 'h:i A');
            }
            },{
                xtype: 'numberfield',
                fieldLabel: 'OUT TIME',
                name: 'outtime',
                renderer: function(value, metaData){
                return Ext.Date.format(value, 'h:i A');
            }
            }
            ]
        }
        ];
        this.buttons = [
        {
            text: 'Save',
            action: 'save'
        },
        {
            text: 'Cancel',
            scope: this,
            handler: this.close
        }
        ];
        this.callParent(arguments);
    }
});

我在网格行中双击调用此窗口的控制器如下所示:

Ext.define('Ext4Example.controller.Attendences', {
    extend: 'Ext.app.Controller',
    stores: [
    'Attendences','Months'
    ],
    models: [
    'Attendence','Month'
    ],
    views: [
    'attendence.Timeperiod','attendence.Details','attendence.Attendencewindow','attendence.Editattendence','attendence.Datagrid'  //'attendence.Months'
    ],

    refs: [{
        ref: 'stockaddForm',
        selector: 'form'
    }],

    init: function () {
        this.control({
            'datagrid': {
                itemdblclick: this.editUser,
                viewready: this.attnready
            },
            'attendencewindow button[action=save]': {
                click: this.save
            }       
        });
    },

    editUser: function(grid, record){
        var view = Ext.widget('editattendence');
        view.down('form').loadRecord(record);
    },
    save: function(){
        var today = new Date();
        var dd = today.getDate();
        var mm = today.getMonth()+1; //January is 0!
        var yyyy = today.getFullYear();     //+1
        Ext.Msg.alert("Today is - ",dd+" - "+mm+" - "+yyyy);
    },
    attnready: function(grid, eOpts) {       
        console.log('hello');
        var store = grid.getStore(),
        selModel = grid.getSelectionModel();
          if (store.getAt(0)) {
            selModel.select(0);
        }
    }
});
4

1 回答 1

2

嘿,我已经解决了这个问题。只需在editAttendence 表单中进行一点更改,如下所示:

Ext.define('Ext4Example.view.attendence.Editattendence' ,{
    extend: 'Ext.window.Window',
    alias : 'widget.editattendence',
    title: 'Edit Attendence',
    layout: 'fit',
    autoShow: true,
    initComponent: function () {
        this.items = [
        {
            xtype: 'form',

            bodyStyle: {
                background: 'none',
                padding: '10px',
                border: '0'
            },
            items: [
            {
                xtype: 'datefield',
                name: 'id',
                allowBlank: false,
                fieldLabel: 'Attendene ID'
            },
            {
                xtype: 'datefield',
                format:'h:i A',
                name: 'intime',
                allowBlank: false,
                fieldLabel: 'IN TIME'

            },{
                xtype: 'datefield',
                format:'h:i A',
                fieldLabel: 'OUT TIME',
                allowBlank: false,
                name: 'outtime'

            }
            ]
        }
        ];
        this.buttons = [
        {
            text: 'Save',
            action: 'save'
        },
        {
            text: 'Cancel',
            scope: this,
            handler: this.close
        }
        ];
        this.callParent(arguments);
    }
});
于 2012-11-26T05:15:49.870 回答