Results 1 to 4 of 4

Thread: adding copied records does not update idIndex in ArrayReader.

  1. #1
    Ext JS Premium Member
    Join Date
    Jan 2010
    Posts
    12

    Default adding copied records does not update idIndex in ArrayReader.

    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.');
    
    });

  2. #2
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,892

    Default

    Why would the Record change its ID upon copy? To what? How?

    If you want to change its ID, pssthe new ID into the copy call as described in the API docs.

  3. #3
    Ext JS Premium Member
    Join Date
    Jan 2010
    Posts
    12

    Default

    I got around this by setting the record.id directly. I'm not sure if will cause any other issues, but seems to work.
    Code:
        Ext.each(records,
            function(r)
            {            
                // Copy records for data store
                var r2 = r.copy();
                r2.id = r.get('nm');
                tstStore2.add(r2);
            },

  4. #4
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,892

    Default

    Did you read the API docs for copy as I suggested???

Similar Threads

  1. Adding new records to a JsonStore to update a GridPanel
    By MrTim in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 15 Feb 2010, 4:28 AM
  2. XmlStore always uses POST instead of PUT to update records
    By MrRob in forum Ext 3.x: Help & Discussion
    Replies: 2
    Last Post: 3 Jan 2010, 11:17 PM
  3. Adding records to a JsonStore
    By andyd01 in forum Ext 3.x: Help & Discussion
    Replies: 8
    Last Post: 2 Dec 2009, 3:23 PM
  4. Adding new records to a store
    By BlueCamel in forum Ext 3.x: Help & Discussion
    Replies: 6
    Last Post: 31 Aug 2009, 2:26 PM
  5. [FIXED][3.x] ArrayReader does not "see" idIndex: 0
    By Animal in forum Ext 3.x: Bugs
    Replies: 9
    Last Post: 14 May 2009, 3:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •