使用Ext.form.updateRecord()上传文件

时间:2012-07-10 13:24:31

标签: forms file-upload extjs extjs4

ExtJS 4.1。

让我们假设我们有一些形式:

Ext.define('App.view.editform', {
    extend: 'Ext.form.Basic',
    defaultType: 'textfield',
    items: [
        {
            fieldLabel: 'Title',
            name: 'title',
            allowBlank: false,
        }, {
            xtype: 'textarea',
            fieldLabel: 'Text',
            name: 'text',
            height: 160,
        }, {
            xtype: 'filefield',
            fieldLabel: 'Image',
            name: 'image',
        }, {
            xtype: 'hidden',
            name: 'id',
        }, 
    ],

});

和商店:

    Ext.define('App.store.Store', {

    extend: 'Ext.data.Store',
    model: new Ext.data.Model({
        fields: [
            {name: 'id', type: 'int'},
            {name: 'title', type: 'string'},
            {name: 'text', type: 'string'},
        ],
        proxy: {
            type: 'ajax',
            url: '/someurl',
            reader: {
                type: 'json',
                root: 'results'
            },
        },
    }),
    autoLoad: true,
    autoSync: true,

});

要修改Records中的Store,我们可以在表单和loadRecord();方法上使用updateRecord();方法将更改提交到Store(然后再提交给服务器) 。但是在服务器上,每个Record都有与之关联的图像。

updateRecord();方法仅向Store提交文本字段。 Model不能包含binary类型字段。

那么有没有办法使用表单updateRecord();方法上传图片?

1 个答案:

答案 0 :(得分:0)

没有。在服务器端必须有这个特殊的处理程序。