-
28 Apr 2011 8:05 AM #1
[FIXED-EXTJSIV-1818][4.0.0] record.destroy() callbacks not executed
[FIXED-EXTJSIV-1818][4.0.0] record.destroy() callbacks not executed
I am deleting a node from a tree and I want to use the callbacks to see whether the serverside action has been successful.
Sadly, the destroy method doesn't seem to work. As a workaround I can call the doRequest method on the proxy.
Code:var store = this.getStructuresStore(), //Ext.data.TreeStore record = tree.getView().getSelectedRecords()[0]; // Callbacks not executed record.destroy({ failure: function () { console.log('destroy failure!'); }, success: function () { console.log('destroy success!'); }, callback: function () { console.log('destroy callback!'); } }); // This works var operation = new Ext.data.Operation({ action: 'destroy', id: record.getId() }); store.getProxy().doRequest(operation, function () { console.log('request callback'); });
-
28 Apr 2011 8:16 AM #2
Can't reproduce this:
Server returns:Code:Ext.define('Item', { extend: 'Ext.data.Model', fields: ['id', 'foo'], proxy: { type: 'ajax', url: 'data.json' } }); Ext.onReady(function() { var rec = new Item({ id: 1, foo: 'bar' }, 1); rec.destroy({ success: function(){ console.log('success'); }, callback: function(){ console.log('callback'); }, failure: function(){ console.log('failure'); } }); });
Code:{"success": true}Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
28 Apr 2011 8:30 AM #3
To be more specific:
The Ext.data.Model.destroy() method works, it performs the ajax request, but the succes/failure callbacks are not executed.
If I use record.save() or the Ext.data.proxy.Rest.doRequest() everything works fine.
-
28 Apr 2011 8:36 AM #4
As I said above, I can't reproduce it, the callbacks fire just fine for me.
Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
29 Apr 2011 12:40 AM #5
callbacks are not working for some unknown reason.
callbacks are not working for some unknown reason.
//I define a Flow model as follows(Using some rest):
Ext.define('Flow', {
extend : 'Ext.data.Model',
fields : [ {
name : 'id',
type : 'int'
}, {
name : 'name',
type : 'string'
}, {
name : 'owner',
type : 'string'
}, {
name : 'ctime',
type : 'string'
} ],
proxy : {
type : 'rest',
url : '/flow',
reader : 'json'
}
});
//selModel is a instance of Flow. It can be destroyed, but the callbacks(success, failure, callback) are not be called.
selModel.destroy({
success : function() {
console.log('success?');
},
failure : function() {
console.log('fail?');
},
callback : function(record, operation) {
console.log('callback');
}
});
//Enjoy the question!
-
2 May 2011 2:03 AM #6
New example code
New example code
The following code renders a treePanel with a treeStore and an ajax proxy. I've put 2 buttons in the toolbar which both select a node and then destroy the selected record. The first button calls the destroy method on the record and these callbacks do not work (the request is made twice, so that's also a bit strange). The second button uses the proxy doRequest method and this callback works.
Hopefully this code will give a better explaination (and will be probably show that I am doing something stupid
)
PHP Code:var store = Ext.create('Ext.data.TreeStore', {
root: {
expanded: true,
text: "root",
children: [{
id: 1,
text: "Node 1.1",
leaf: true
},{
id: 2,
text: "Node 1.2",
leaf: true
},{
id: 3,
text: "Node 1.3",
leaf: true
},{
id: 4,
text: "Node 1.4",
leaf: true
},{
id: 5,
text: "Node 1.5",
leaf: true
}]
},
proxy: {
type: 'ajax',
url: 'delete.json' // Returns { "success" : true }
}
});
Ext.onReady(function () {
var tree = Ext.create('Ext.tree.Panel', {
title: 'Model (record) destroy test',
width: 300,
height: 400,
store: store,
renderTo: Ext.getBody(),
tbar: [{
xtype: 'button',
text: 'record.destroy',
handler: function () {
var record,
selModel = tree.getView().getSelectionModel();
// Select 2nd record
selModel.select(1);
// Get record
record = selModel.getSelection()[0];
console.log('record', record);
// Callbacks not executed
record.destroy({
failure: function () {
console.log('destroy failure!');
},
success: function () {
console.log('destroy success!');
},
callback: function () {
console.log('destroy callback!');
}
});
}
}, {
xtype: 'button',
text: 'proxy.doRequest',
handler: function () {
var record,
operation,
selModel = tree.getView().getSelectionModel();
// Select 2nd record
selModel.select(1);
// Get record
record = selModel.getSelection()[0];
console.log('record', record);
operation = new Ext.data.Operation({
action: 'destroy',
id: record.getId()
});
// This callback works
tree.getStore().getProxy().doRequest(operation, function () {
console.log('doRequest callback');
});
}
}]
});
});
-
2 May 2011 5:10 AM #7
Ok I see, it's something specifically affecting models decorated with NodeInterface. This should be resolved in the next release.
Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
2 May 2011 5:24 AM #8
OK, thanks!
-
8 Feb 2013 10:49 AM #9
I'm using 4.1.1a and i'm still having this problem.
Thank you for reporting this bug. We will make it our priority to review this report.
Similar Threads
-
[FIXED-EXTJSIV-931]Combobox typeahead clears box if no record found
By hulstein in forum Ext:BugsReplies: 1Last Post: 12 Apr 2011, 8:40 PM -
[FIXED-EXTJSIV-879][B2] Error when adding record to Combo w/ SessionStorageProxy
By Sébastien.Volle in forum Ext:BugsReplies: 2Last Post: 10 Apr 2011, 11:31 PM -
[FIXED-EXTJSIV-841][B2] Ext.AbstractPlugin init/destroy method
By gabriele.muscas in forum Ext:BugsReplies: 0Last Post: 9 Apr 2011, 12:58 AM -
[FIXED-EXTJSIV-314] WebStorageProxy: getRecord() doesn't set id property for record
By uzver in forum Ext:BugsReplies: 1Last Post: 25 Mar 2011, 6:50 PM -
createSequense on Ext.form.Field.setValue is not executed when a record is loaded.
By RonaldBrinkerink in forum Ext 3.x: Help & DiscussionReplies: 1Last Post: 2 Mar 2011, 3:29 AM


Reply With Quote