Sencha Touch 2 model.save 在更新操作中使用 POST 而不是 PUT

Sencha Touch 2 model.save is using POST instead of PUT in update operation

在 sencha touch 2 中,对现有记录的 model.save() 调用触发 POST 而不是预期的 PUT。

我有以下型号:

Ext.define('HomeInventory.model.Product', {
    extend: 'Ext.data.Model',

    config: {
        idProperty: '_id',
        fields: [
            { name: '_id', type: 'auto' },
            { name: 'name', type: 'string' },
            { name: 'barcode', type: 'string' },
            { name: 'creationDate', type: 'date' },
            { name: 'currentAmount', type: 'number' },
            { name: 'isActive', type: 'boolean'}
        ],
        validations: [
            {type: 'presence', field: 'barcode', message: 'Barcode is required'},
            {type: 'presence', field: 'name', message: 'Name is required'}
        ],
        proxy :{
            type: 'rest',
            url: 'http://localhost:3000/products',
            actionMethods: {
                create: 'POST',
                read: 'GET',
                update: 'PUT',
                destroy: 'DELETE'
            },
        }
    }
});

json 负载包含现有记录预期的 _id 字段,但使用 HTTP POST 而不是 PUT 发送到服务器:

{_id: "575bcd86c0eb22880c7e421e", name: "test product1", barcode: "1234", creationDate: null,…}

在控制器中保存函数调用:

submitProduct: function(){
    Ext.Viewport.setMasked({
        xtype: 'loadmask',
        indicator: true,
        message: 'Saving product...'
    });
    debugger;
    var product = Ext.create('HomeInventory.model.Product');
    this.getProductView().updateRecord(product);
    var validation = product.validate();
    if(validation.isValid){
        var me = this;
        product.save({
            success: function(){
                Ext.Viewport.unmask();
                me.returnToMain();
        },
        failure: function(){
            Ext.Viewport.unmask();
            Ext.Msg.alert('There was an error updating the product');
            me.returnToMain();
        }
      });
    }else{
        //Show validation error
    }
}

这是怎么回事?

好吧,我找到了解决办法。在调用保存方法之前,需要在产品上设置 phantom = false