Reputation: 823
I have defined a Delete function which will delete the record on Gridpanel but somehow it does not do anything! During debugging it comes rec.destroy
section and then skip whole the code block; with no error, no XHR request, just nothing.
I have wondered maybe that's happening because of rec
variable not loading but quite the contrary it's getting required data inside.
Why is that could be happening?
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 (just after suggestion of @scebotari66):
Still getting error after define erase method. (I've update the the 'doDeleteEmployee' function above)
I got idea for erase
but this the result after debugging process:
1. During debugging, it comes to rec.erase
and skip the rest block which inside. When i tried go step by step, i've noticed; it keeps correct data till afterDrop()
function of ext-debug.js.
2. I have defined two console.log -as you will notice above- and it displays only the 'success step one'.
3. In Network tab of Dev-Tool's, there is XHR request but somehow it sends with HTTP: POST method and gets 200-OK as response. So i thought, maybe I am doing something wrong with Model and added below.
The error:
Uncaught TypeError: Cannot read property 'indexOf' of undefined
Model:
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
}
}
});
Upvotes: 0
Views: 231
Reputation: 3480
If you want to destroy the record via the proxy, you should use the erase method.
The destroy method is inherited by Ext.data.Model from Ext.Base, and it's not usually directly invoked when dealing with models.
This method is called to cleanup an object and its resources. After calling this method, the object should not be used any further.
Updated
success
callback will be called.POST
request. This is how the ajax proxy works. If you want to customize this, you need to take a look at the actionMethods config.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.
Upvotes: 2