ExtJS的。更新网格后,Ext.data.DirectStore将空数据发送到服务器

时间:2010-12-10 14:52:44

标签: javascript extjs

我将Ext.data.DirectStore中的数据保存到服务器

时遇到问题

这是我的代码:

new Ext.data.DirectStore({
    api: {
        read: AbonApi.cities,
        create: AbonApi.cities_create,
        update: AbonApi.cities_update,
        destroy: AbonApi.cities_destroy
    },
    paramsAsHash: false,
    autoSave: false,
    storeId: 'cities-store',
    reader: new Ext.data.JsonReader({
        root: 'data',
        idProperty: 'id',
        fields: [
            'id',
            'name',
            'label',
            'comment',
        ]
    }),
    writer: new Ext.data.JsonWriter({
        encode: true,
        writeAllFields: true,
        listful: true
    })
});

Ext.ux.CityGrid = Ext.extend(Ext.grid.EditorGridPanel,{
    initComponent: function(){
        var config = {
            frame:true,
            title: 'Cities',
            height:200,
            width:500,
            store: 'cities-store',
            closable: true,
            tbar: [{
                text: 'Apply',
                handler: function() {
                    this.store.save()
                },
                scope: this
            }],
            columns: [
                {header: "Id", dataIndex: 'id', editor: new Ext.form.TextField()},
                {header: "Name", dataIndex: 'name', editor: new Ext.form.TextField()},
                {header: "Label", dataIndex: 'label', editor: new Ext.form.TextField()},
                {header: "Comment", dataIndex: 'comment', editor: new Ext.form.TextField()},
            ],
            onRender:function() {
                Ext.ux.CityGrid.superclass.onRender.apply(this, arguments);
                this.store.load();
            }
        }
        Ext.apply(this, Ext.apply(this.initialConfig, config));
        Ext.ux.CityGrid.superclass.initComponent.apply(this, arguments);
    }
});

在按下Apply按钮编辑网格后,我可以在firebug中看到这样的POST数据:

{"action":"AbonApi","method":"cities_update","data":null,"type":"rpc","tid":7}

为什么data为空,我对网格的更改在哪里? 我做错了什么或这是一个错误

更新:

Ext.ux.CityGrid
... cutted out ...

        tbar: [{
            text: 'Apply',
            handler: function() {
                modified = this.store.getModifiedRecords();
                console.log(modified)                   
                this.store.save()
            },
            scope: this
        }],

... cutted out ...

我可以在保存商店之前在控制台中看到修改过的数据。并且此数据未传递到服务器;

1 个答案:

答案 0 :(得分:1)

为JsonWriter设置“encode:false”。测试创建和销毁。 我在那里找到了它:http://www.sencha.com/forum/showthread.php?80958-DirectStore-and-write-function