2017-08-03 27 views
0

我已經定義了刪除功能,它將刪除在Gridpanel上的記錄,但不知何故它什麼也不做!在調試過程中,會出現rec.destroy部分,然後跳過整個代碼塊;沒有錯誤,沒有XHR請求,只是沒有。刪除功能不能在ExtJS 5.1.1中運行

我想知道這可能是因爲rec變量沒有加載而發生,相反它正在獲取所需的數據。

爲什麼會發生這種情況?

doDeleteEmployee: function() { 
var me = this; 
var rec = me.getEmployeeForm().getRecord(); 
Ext.MessageBox.confirm('Confirm Delete User', 'Are you sure you want to delete user ' + rec.get('firstName') + '?', function (btn) { 
    if (btn === 'yes') { 
     rec.erase({ 
       success: function(rec, operation) { 
        console.log('success step one'); 
        me.getStore().load(); 
        console.log('success step two'); 
        Ext.MessageBox.alert('INFO', 'Delete Success'); 
       }, 
       failure: function(rec, operation) { 
        console.log('this is failure'); 
        Ext.MessageBox.alert('Delete Failure', operation.request.scope.reader.jsonData.msg); 
       } 
     }); 
    } 
}); 

}

EDIT(只是@ scebotari66的建議後):

仍然得到錯誤之後限定擦除方法。 (我已經更新上面的「doDeleteEmployee」功能)

我有想法erase但這種調試過程後的結果:
1.在調試過程中,涉及到rec.erase並跳過剩下的塊,內。當我嘗試着一步一步的時候,我注意到了;它保持正確的數據,直到afterDrop()函數ext-debug .js。
2.我已經定義了兩個console.log - 你會注意到上面 - 它只顯示'成功的第一步'
3.在Dev-Tool's的Network選項卡中,有XHR請求,但它以HTTP發送:POST方法並獲得200-OK作爲響應。所以我想,也許我正在做一些錯誤的模型,並在下面添加。

錯誤:

Uncaught TypeError: Cannot read property 'indexOf' of undefined 

型號:

Ext.define('Employee.model.EmployeeMdl', { 
     extend: 'Ext.data.Model', 
    requires: ['Ext.data.identifier.Sequential'], 
    identifier: { 
     type: 'sequential', 
     seed: 1223334477, 
     increment: 10 
    }, 
    fields: [ 
     {name: 'firstName', type: 'string'}, 
     {name: 'lastName', type: 'string'}, 
     {name: 'email', type: 'string'} 
    ], 
    idProperty: 'id', 
    proxy: { 
     type: 'ajax', 
     headers: { 
      'Content-Type': 'application/json'  
     }, 
     api: { 
      read: 'http://...0.223:8223/orest/employee', 
      create: 'http://...0.223:8223/orest/employee', 
      update: 'http://...0.223:8223/orest/employee', 
      destroy: 'http://...0.223:8223/orest/employee' 
     }, 
     reader: { 
      type: 'json' 
     }, 
     writer: { 
      type: 'json', 
      allowSingle: true, 
      encode: false, 
      writeAllFields: true 
     } 
    } 
}); 

回答

2

如果你想通過代理摧毀的記錄,你應該使用erase方法。

destroy方法由Ext.Base中的Ext.data.Model繼承,在處理模型時通常不會直接調用它。

This method is called to cleanup an object and its resources. After calling this method, the object should not be used any further.

更新

  1. 它,因爲你所得到的錯誤跳過代碼的其餘部分。
  2. 如果您返回成功響應,則會調用success回調。
  3. 發送POST請求是很正常的。這就是ajax代理的工作原理。如果你想定製這個,你需要看看actionMethods配置。

Mapping of action name to HTTP request method. In the basic AjaxProxy these are set to 'GET' for 'read' actions and 'POST' for 'create', 'update' and 'destroy' actions.

+0

親愛的@ scebotari66感謝您的回覆。我更新了代碼片段的一些信息。希望你有時間檢查它。 –

+0

你如何創建記錄。您是單獨加載它,還是在加載商店時創建它? – scebotari66

+0

我想刪除數據庫上創建的記錄。所以記錄會在我加載商店時創建。 –