If I run the sample code below, the getById() method on tstStore2 fails to find the record. Looking at the tstStore2 data in Firebug, it seems as if the records kept the idIndex defined from the store they were copied from. So the copied records in tstStore2 still have the id (idIndex 0) set.
Is there a call needed beyond store.add() to get the indexes to update?
Code:
Ext.onReady(function()
{
var tstData = [[1,'Name1'],[2,'Name2'],[3,'Name3']];
var tstStore = new Ext.data.ArrayStore(
{
autoDestroy: true,
storeId: 'testStore',
idIndex: 0,
fields:
[
{ name: 'id', type: 'int' },
{ name: 'nm', type: 'string' }
]
});
var tstStore2 = new Ext.data.ArrayStore(
{
autoDestroy: true,
storeId: 'testStore',
idIndex: 1,
fields:
[
{ name: 'id', type: 'int' },
{ name: 'nm', type: 'string' }
]
});
tstStore.loadData(tstData);
// Now can we get by Id
var testID = 2;
var aRecord = tstStore.getById(testID);
if (aRecord != null)
alert(aRecord.get('nm') + ' was found by id ' + testID);
else
alert('record by id ' + testID + ' not found.');
// Copying Records into new store leaves same index information
var records = tstStore.getRange();
Ext.each(records,
function(r)
{
// Copy records for data store
tstStore2.add(r.copy());
},
this
);
// Now can we get by second index?
var testID2 = 'Name3';
// ***** The following method fails since record seems to still show idIndex: 0 as id ******
var aRecord2 = tstStore2.getById(testID2);
if (aRecord2 != null)
alert(aRecord2.get('nm') + ' was found by id ' + testID2);
else
alert('record by id ' + testID2 + ' not found.');
});