我已经定义了一个Delete功能,它将删除Gridpanel上的记录但不知何故它什么也没做!在调试期间,它会出现rec.destroy
部分,然后跳过整个代码块;没有错误,没有XHR请求,只是没有。
我想知道可能因为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);
}
});
}
});
}
编辑(在建议@ scebotari66之后):
定义擦除方法后仍然出现错误。 (我已更新上面的' doDeleteEmployee'函数)
我对erase
有所了解,但这是调试过程后的结果:
1.在调试期间,它来到rec.erase
并跳过里面的其余块。当我尝试一步一步走的时候,我已经注意到了;它保持正确的数据,直到 ext-debug .js的afterDrop()
功能
2.我已经定义了两个console.log - 您将在上面注意到它 - 它只显示'成功第一步' 。
3.在Dev-Tool的网络选项卡中,有 XHR 请求但不知何故它通过HTTP发送: POST 方法并获得200-OK作为响应。所以我想,也许我在使用Model做错了,并在下面添加。
错误:
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
}
}
});
答案 0 :(得分:2)
如果您想通过代理销毁记录,则应使用erase方法。
destroy方法由Ext.Base中的Ext.data.Model继承,并且在处理模型时通常不会直接调用它。
调用此方法来清理对象及其资源。后 调用此方法时,不应再使用该对象。
<强>更新强>
success
回调。POST
请求是正常的。这就是ajax代理的工作原理。如果要自定义此选项,则需要查看actionMethods配置。将操作名称映射到HTTP请求方法。在基本的AjaxProxy中 这些都设置为&#39; GET&#39;为了阅读&#39;行动和&#39; POST&#39;为&#39;创建&#39;, &#39;更新&#39;并且&#39;销毁&#39;动作。