2016-06-15 54 views
3

在sencha touch中,对现有记录中的model.save()进行的2次调用是按照预期触发POST而不是PUT。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 
    } 
} 

这里有什么问题?

回答

2

嗯,我找到了一个解决方案。在调用保存方法之前,必须在产品上设置phantom = false