I need to add a non-phantom record from one store (ItemStore) into another (ItemEvaluacionStore). The record has already id assigned, so the getNewRecords function returns an empty array, instead an array with the new records I've already inserted.
In the documentation says the following:
getNewRecords( ) : Ext.data.Model[]
Returns all Model instances that are either currently a phantom (e.g. have no id), or have an ID but have not yet been saved on this Store (this happens when adding a non-phantom record from another Store into this one)Available since: 4.0.0
I used insert and add method, but got the same result. The record is actually added to the itemEvaluacionStore, as I can see when I print the record in the console. I'm using ExtJS 4.1.1 by the way.
How can I get the new records inserted in itemEvaluacionStore? Please see the code of the stores and models below:
ItemStore:
Ext.define('RH.store.evaluaciones.ItemStore', {
extend: 'Ext.data.Store',
model: 'RH.model.evaluaciones.Item',
autoLoad: true,
autoSync: false
});
Item:
Ext.define('RH.model.evaluaciones.Item', {
extend: 'Ext.data.Model',
fields: [
'id', 'nombre_item', 'descripcion_item'
],
proxy: {
type: 'rest',
method: 'get',
url: 'app/proxy.evaluacion.php',
extraParams: {
act: 'getAllItems'
},
reader: {
type: 'json',
root: 'results',
successProperty: 'success'
}
}
});
ItemEvaluacionStore:
Ext.define('RH.store.evaluaciones.ItemEvaluacionStore', {
extend: 'Ext.data.Store',
model: 'RH.model.evaluaciones.ItemEvaluacion'
});
ItemEvaluacion:
Ext.define('RH.model.evaluaciones.ItemEvaluacion', {
extend: 'Ext.data.Model',
fields: [
'id', 'nombre_item', 'descripcion_item'
],
autoSync: true,
proxy: {
type: 'ajax',
method: 'GET',
url: 'app/proxy.evaluacion.php',
params: {
act: 'getItems'
},
reader: {
type: 'json',
root: 'results',
successProperty: 'success'
}
}
});
Code of the record adding to store:
var stoEv = Ext.getStore('evaluaciones.ItemEvaluacionStore');
var newRec = Ext.create('RH.model.evaluaciones.ItemEvaluacion',
{
nombre_item: item.data.nombre_item,
descripcion_item: item.data.descripcion_item,
id: item.data.id
});
stoEv.insert(0,newRec);