2017-08-03 24 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

我想删除数据库上创建的记录。所以记录会在我加载商店时创建。 –