我已经定义了删除功能,它将删除在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
}
}
});
亲爱的@ scebotari66感谢您的回复。我更新了代码片段的一些信息。希望你有时间检查它。 –
你如何创建记录。您是单独加载它,还是在加载商店时创建它? – scebotari66
我想删除数据库上创建的记录。所以记录会在我加载商店时创建。 –