2013-06-04 77 views
0

我是新來的extjs和我正面臨一個問題,我真的不明白爲什麼它不工作。我正嘗試從我的網格,其中填充網格數據庫中刪除行,但我的客戶說,沒有刪除我的服務器上(抱歉不好英語)刪除路徑未找到,存儲代理錯誤?

這裏是我的代碼:

店:

Ext.define('LU.store.Audios', { 
    extend: 'Ext.data.Store',  
     autoLoad: true, 
     autoSync: true, 
     model: 'LU.model.Audio', 

     proxy: { 
      type: 'rest', 

      api: { 
       create: 'http://localhost:3000/upload', 
       read: 'http://localhost:3000/list', 
       update: 'http://localhost:3000/update', 
       destroy: 'http://localhost:3000/delete' 
      }, 

      reader: { 
       type: 'json', 
       root: 'audios', 
       totalProperty : 'total', 
       successProperty: 'success' 
      }, 
      writer: { 
       type: 'json' 
      }  

     } 


    }); 

型號:

Ext.define('LU.model.Audio', { 
    extend: 'Ext.data.Model', 
    fields: [ 
     { name: 'id', type: 'int'}, 
     { name: 'name', type: 'string'}, 
     { name: 'path', type: 'string'} 
    ], 

}); 

視圖:

Ext.define('LU.view.Main', { 
    extend: 'Ext.panel.Panel', 
    alias: 'widget.mainview', 
    id: 'main', 





    initComponent: function() { 

     this.items = [{ 

     }, { 
      xtype: 'grid', 
      title: 'Audio liste', 
      store: 'Audios', 
      id: 'mygrid', 

      columns: [ 
       {text: 'Dateiname', dataIndex: 'name'}, 
       {text: 'Dateipfad', dataIndex: 'path'} 
      ], 
      listeners : { 
       afterrender : function (grid) { 
         grid.addDocked({ 
          xtype: 'toolbar', 
          dock: 'top', 
          items: [{ 
           text: 'Delete', 
           action: 'delete' 
          }, { 
           text: 'Download' 
          }] 
         }); 
        } 

      }, 

     } 
     ]; 
     this.callParent(arguments); 
    } 
}); 

和控制器:

Ext.define('LU.controller.MainController', { 
    extend: 'Ext.app.Controller', 

    views: ['Main'], 
    stores: ['Audios'], 
    models: ['Audio'], 

    init: function() { 
     this.control({ 

     'mainview button[action=delete]': { 
       click: this.delete 
     } 


     }); 

    }, 

    delete: function() { 
     var grid = Ext.getCmp('mygrid'); 
     var row = grid.getSelectionModel().getSelection(); 

     Ext.getStore("Audios").remove(row); 


    }, 



}); 

和服務器:

​​3210

回答

0

當使用Ext.data.proxy.Rest,用於刪除/遙遠而明亮操作的默認actionMethod是HTTP DEL ETE動詞。因此,您應該確保您的Web服務器設置允許使用此HTTP動詞。我遇到過一些負載均衡器甚至沒有實現DELETE動詞的問題,這使得Rest代理中的默認動作不可行。

當然,您可以更改通過DELETE操作發送的VERB。例如,您可以將其更改爲PUT,並且仍然可以獲得與DELETE相同的行爲indempotent

+0

感謝您的建議,只是發現了什麼問題,而我試圖改變VERB。在我的服務器上,我忘了添加「:id」到刪除路徑,所以它應該喜歡這個app.delete('/ delete /:id',function(req,res){} – Adrian