PDA

View Full Version : Ext.data.model not have the function destroy



posoci
28 Sep 2011, 8:33 AM
I'm trying to use rest proxy on store in sencha touch, I follow the example in documentation of the
module Ext.data.Model http://dev.sencha.com/deploy/touch/docs/output/Ext.data.Model.html
The methods create, load and save work, but the destroy returning the error

!important]Uncaught TypeError: Object function (){ superclass.apply(this, arguments); } has no method 'destroy' !important](anonymous function)

I had research the source code, but not found reference of the function destroy.




Ext.regModel('User', { fields: ['id', 'name', 'email'], proxy: { type: 'rest', url : '/users.php',
reader: {
type: 'json',
root: 'records',
totalProperty: 'total'
},
writer:{
type: 'json',
encode: false
}
} });
var User = Ext.ModelManager.getModel('User');
User.load(123, { success: function(user) { console.log(user.getId()); //logs 123 }
});

//not work because class Ext.data.model of sencha touch
//doesn't have the function destroy
//call the function destroy cause the error below
//Uncaught TypeError: Object function (){ superclass.apply(this, arguments); } has no method 'destroy'

user.destroy({ success: function() { console.log('The User was destroyed!'); } });
[/COLOR]

tomalex0
28 Sep 2011, 8:08 PM
I have came also came across same problem, but i was able get a workaround from forum itself, but i couldn't recollect the post.

This works for me


Ext.override(Ext.data.Model, {
destroy: function(options) {
var me = this,
action = 'destroy';
options = options || {};
Ext.apply(options, {
records: [me],
action: action
});


var operation = new Ext.data.Operation(options),
successFn = options.success,
failureFn = options.failure,
callbackFn = options.callback,
scope = options.scope;
var callback = function(operation) {
if (operation.wasSuccessful()) {
if (typeof successFn == 'function') {
successFn.call(scope, record, operation);
}
} else {
if (typeof failureFn == 'function') {
failureFn.call(scope, record, operation);
}
}


if (typeof callbackFn == 'function') {
callbackFn.call(scope, record, operation);
}
};
me.getProxy()[action](operation, callback, me);
return me;
}
});

lpfx
6 Oct 2011, 6:04 AM
I'm using the override that you post for the detroy method, but I can get the return of the method (if it was successful or not).

Does anyone know how to do this?

Example:


rec.destroy({
success : function() {
// something here (nothing happens here)
},
failure : function() {
// something here (nothing happens here)
}
});

tomalex0
6 Oct 2011, 12:15 PM
I have made small changes in the override and i was able to get call back




Ext.override(Ext.data.Model, {
destroy: function(options) {

var me = this,
action = 'destroy';
options = options || {};
Ext.apply(options, {
records: [me],
action: action
});


var operation = new Ext.data.Operation(options),
successFn = options.success,
failureFn = options.failure,
callbackFn = options.callback,
scope = options.scope,
record;

var callback = function(operation) {
record = operation.getRecords()[0];
if (operation.wasSuccessful()) {
if (typeof successFn == 'function') {
successFn.call(scope, record, operation);
}
} else {
if (typeof failureFn == 'function') {
failureFn.call(scope, record, operation);
}
}


if (typeof callbackFn == 'function') {
callbackFn.call(scope, record, operation);
}
};

me.getProxy()[action](operation, callback, me);
return me;
}
});