PDA

View Full Version : function "destroy" of memory storage throws error



phamtranquocviet
19 Jun 2013, 6:02 PM
Hi,

I get the following error when calling "destroy" function of a store whose proxy's storage type is "memory":

TypeError: recs is null
len = recs.length;

Here is how function "destroy" is called:


function handlePostDeleteChild() {
console.log("done...");
}

function handleDeleteChild(deleteButton, event) {
var store, window, formValues, operation;

window = deleteButton.up().up();
formValues = window.down("form").getForm().getValues(); => formValues is shown in blue below
operation = Ext.create("Ext.data.Operation", { action: "destroy", params: formValues });
store = Ext.StoreManager.lookup('children-store');
store.getProxy().destroy(operation, handlePostDeleteChild, window);
}


Object { firstName="Quyen", lastName="Nguyen", gender="female", more...}

and here is the definition of the store inside my grid:


function getChildrenUi() {
return {
xtype: 'fieldset',
title: "<span style='font-weight:bold'>Children Information</span>",
checkboxToggle: false,
layout: 'anchor',
items: [
Ext.create('Ext.grid.Panel', {
height: 130,
sortableColumns: false,
enableColumnHide: false,
margin: '0 0 8 0',
id: 'children-grid',
store: Ext.create("Ext.data.Store", {
proxy: { type: 'memory' },
storeId:"children-store",
model: 'Child',
autoLoad: false
}),
columns: [
new Ext.grid.RowNumberer(),
{ text: 'First Name', dataIndex: 'firstName', flex: 0.2},
{ text: 'Last Name', dataIndex: 'lastName', flex: 0.2},
{ text: 'Gender', dataIndex: 'gender', align: 'center', flex: 0.2 },
{ text: 'Date of Birth', dataIndex: 'dateOfBirth', align: 'center', flex: 0.2},
{ text: 'Grade Entering', dataIndex: 'gradeEntering', align: 'center', flex: 0.2}
],
dockedItems: [{
xtype: 'toolbar',
dock: 'bottom',
items: [
{xtype: 'label', id: 'children-error', cls: 'error'},
'->',
getAddChildUi(),
getDeleteChildUi()
]
}]
})
]
};
}


Thanks for your help

tvanzoelen
20 Jun 2013, 12:17 AM
What happens if you do this?


store: Ext.create("Ext.data.Store", {
proxy: { type: 'memory' },
data: [],
storeId:"children-store",
model: 'Child',
autoLoad: false
}),

I mean setting data: [] in the store config

phamtranquocviet
20 Jun 2013, 5:37 AM
Hi,
I tried "data: []" and get a similar error:

TypeError: recs is null
len = recs.length;

I am beginnign to think this is a extjs bug because
1) I can see the record I am trying to destroy on the grid
2) console.log(store.findRecord('firstName, 'Quyen') returns a valid records
3) console.log(getNewRecords()) returns an empty array like this: []
4) console.log(getUpdatedRecords()) returns an empty array like this: []

Could folks from sencha comment on this please?

tvanzoelen
20 Jun 2013, 11:15 PM
I do not understand what you want to do with the destroy method, because it is doing nothing much.You create an operation but it is not loaded with records


operation = Ext.create("Ext.data.Operation", { action: "destroy", params: formValues });

you see no records in this operation, then your bug is in this method, operation.getRecords returns a null. You could override this method and set



updateOperation: function(operation, callback, scope) {
var i = 0,len =0,
recs = operation.getRecords(),

if(recs){
len = recs.length;
}

for (i; i < len; i++) {
recs[i].commit();
}
operation.setCompleted();
operation.setSuccessful();

Ext.callback(callback, scope || this, [operation]);
},

but again why do you destroy the proxy?

slemmon
21 Jun 2013, 1:51 PM
I was wondering the same thing - why call destroy() from the proxy?
Generally you won't call that method directly. Normally you'll just remove the record from the store and sync(). Is removing the record from the store the end goal?