Extjs 为什么';t getUpdateRecords()返回Ext JS属性网格中已修改记录的列表?

Extjs 为什么';t getUpdateRecords()返回Ext JS属性网格中已修改记录的列表?,extjs,extjs4,Extjs,Extjs4,请试一试 打开控制台,运行JSFIDLE,更改属性值,然后单击“将状态写入控制台” 为什么商店仍然报告零更新记录?它知道该属性的新值 这是JSFIDLE中的Ext JS 4.2代码: Ext.onReady(function() { Ext.define('KitchenSink.view.grid.PropertyGrid', { extend: 'Ext.container.Container', requires: [ 'Ext.button.

请试一试

打开控制台,运行JSFIDLE,更改属性值,然后单击“将状态写入控制台”

为什么商店仍然报告零更新记录?它知道该属性的新值

这是JSFIDLE中的Ext JS 4.2代码:

Ext.onReady(function() {    


Ext.define('KitchenSink.view.grid.PropertyGrid', {
    extend: 'Ext.container.Container',

    requires: [
        'Ext.button.Button',
        'Ext.grid.property.*',
        'Ext.layout.container.VBox',
        'Ext.layout.container.HBox'
    ],
    xtype: 'property-grid',


    height: 275,
    width: 300,
    layout: {
        type: 'vbox',
        align: 'stretch'
    },

    initComponent: function(){
        Ext.apply(this, {
            items: [{
                xtype: 'container',
                layout: 'hbox',
                margin: '0 0 10 0',
                defaultType: 'button',
                items: [{
                    text: 'Write state to console',
                    margin: '0 0 0 10',
                    scope: this,
                    handler: this.onWriteStateClick
                }]
            }, {
                xtype: 'propertygrid',
                source: {
                    weight: 0.01,
                    distance: 1
                }
            }]
        });
        this.callParent();
    },

    onWriteStateClick: function(){
        var grid = this.down('propertygrid');

        var store = grid.getStore();
        console.log("Number of new records: " + store.getNewRecords().length);
        console.log("Number of updated records: " + store.getUpdatedRecords().length);
        console.log("Number of deleted records: " + store.getRemovedRecords().length);

        store.each(function (rec) {
            console.log("store says --> key: " + rec.get("name") + ", value: " + rec.get("value"));
        });

        //var source = grid.getSource();
        //Object.keys(source).forEach(function(key) {
        //    console.log("source says --> key: " + key + ", value: " + source[key]);
        //});
    },


});


Ext.create('KitchenSink.view.grid.PropertyGrid', { renderTo: Ext.getBody() });


});

简而言之,
属性网格
使用内存代理,它不跟踪修改的记录

详细的回答是,新的/删除的/更新的跟踪只针对服务器代理实现,或者更具体地说,针对持久化到服务器的字段实现。客户端代理(如内存代理)不需要此功能,因为它从不与服务器同步

关于这一点的更深入解释,请参见以下代码:

您可以看到,如果字段没有持久化(就像客户端代理永远不会持久化一样),它就不会获得
dirty
标志,没有它,存储就不会收集记录已更改的信息

即使要为模型字段定义persist,同步机制也需要一个id字段

因此,总结一下,您无法通过客户端代理实现这一点,就像您的示例中在幕后使用的代理一样

if (field && field.persist) {
    if (modified.hasOwnProperty(name)) {
        if (me.isEqual(modified[name], value)) {
            // The original value in me.modified equals the new value, so
            // the field is no longer modified:
            delete modified[name];

            // We might have removed the last modified field, so check to
            // see if there are any modified fields remaining and correct
            // me.dirty:
            me.dirty = false;
            for (key in modified) {
                if (modified.hasOwnProperty(key)){
                    me.dirty = true;
                    break;
                }
            }
        }
    } else {
        me.dirty = true;
        modified[name] = currentValue;
    }
}