简体   繁体   中英

EXTJS Form : How to only update record, not whole record

I made a edit form, to update a comments array with a new comment. Everything good so far.

The store is from MongoDB.

The record has an ISO date, and when I update it, changes it to a string.

From this:

"tmx" : ISODate("2015-07-19T00:26:53.000Z")

to this:

"tmx" : "Sun Jul 19 2015 00:55:23 GMT+0100 (Hora de Verão de GMT)"

Sample record:

"tmx" : ISODate("2015-07-19T00:26:53.000Z"),
"comments" : [{
    "comment" : "tury",
    "date" : "2015-11-19T01:15:13.552Z"
}]

My form:

var form = new Ext.form.FormPanel({
    width: 500,

    items: [{
        xtype: 'grid',
        store: storearray,
        margin: "0 0 10 0",
        columns: [{
            id: 'comment',
            header: "Text",
            autoSizeColumn: true,
            flex: 1,
            sortable: true,
            dataIndex: 'comment'
        }, {
            id: 'date',
            header: "Date",
            dateFormat: 'm-d-Y g:i A',
            autoSizeColumn: true,
            flex: 1,
            sortable: true,
            dataIndex: 'date'
        }],
        layout: {
            type: 'fit',
            align: 'stretch'
        }
    }, {
        xtype: 'textarea',
        id: 'new',
        text: 'Add Comment',
        style: 'width: 100%',
        fieldLabel: 'Add Comment',
        layout: {},
        name: 'comment'
    }],
    dockedItems: [{
        xtype: 'toolbar',
        flex: 1,
        dock: 'bottom',
        ui: 'footer',
        layout: {
            pack: 'end',
            type: 'hbox'
        },
        items: [{
            xtype: 'button',
            text: 'Cancel',
            itemId: 'cancel',
            iconCls: 'cancel'
        }, {
            xtype: 'button',
            text: 'Save',
            itemId: 'save',
            iconCls: 'save',
            handler: function (form, rowIndex, colIndex) {
                var recform = this.up('form').getForm().getRecord();
                var names = recform.get('comments');
                var arraysize = names.length;
                var val = Ext.getCmp('new').getValue();
                var actual = new Date().toISOString();
                if(val == "") {
                    alert('Comentario Vazio');
                } else {
                    names.push({'comment': val, 'date': actual});
                    recform.save();
                    var newRecord = store.sync();
                    this.up('form').getForm().setRecord(newRecord);
                    this.up('form').refresh();
                }
            }
        }]
    }]
});

What I want to do, is just update the field or let my date maintains in ISODate format. and the new comment date be inserted asISODate too.

Any advice?

Update particular field in record/model:

set( fieldName, newValue, [options] ) : String[] Sets the given field to the given value, marks the instance as dirty

Source: Extjs model

In your example if i understand correctly make something like this:

var recform = this.up('form').getForm().getRecord();
var actual = new Date().toISOString();
recform.set('comments', actual);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM