Results 1 to 7 of 7

Thread: Iterating from one ArrayStore to another based on values like

  1. #1

    Default Iterating from one ArrayStore to another based on values like

    I have a data store that looks like this:

    Code:
    var settings = new Ext.data.GroupingStore({
        id: 'settingsStore',
        sortInfo: { field: 'id', direction: 'ASC' },
        url: '/resources/js/app/ptvl/settings2.xml',
        autoload: false,
        reader: new Ext.data.XmlReader({
            record: '>setting',
            idProperty: '@id',
            fields: [
                {name: 'id', mapping: '@id'},
                {name: 'value', mapping: '@value'},
                {name: 'number'}
            ],
            remoteGroup: true,
            groupField: 'number'
    })
    });
    
    settings.load();
    
    settings.on('load', function(store, recs, opt){
        settings.each(function(record){
            var channel_id = record.get('id');
            channel_id = channel_id.split("_");
            record.set('number', channel_id[1]);
        });
    }, this);
    that is populated with this data:

    Code:
    <setting id="Channel_1_type" value="1" />
    <setting id="Channel_1_1" value="Discovery" />
    
    <setting id="Channel_1_rulecount" value="1" />
    <setting id="Channel_1_rule_1_id" value="1" />
    <setting id="Channel_1_rule_1_opt_1" value="Discovery" />
    <setting id="Channel_1_changed" value="False" />
    <setting id="Channel_3_type" value="1" />
    <setting id="Channel_3_1" value="Fuji TV" />
    <setting id="Channel_3_rulecount" value="1" />
    <setting id="Channel_3_rule_1_id" value="1" />
    <setting id="Channel_3_rule_1_opt_1" value="Fuji TV" />
    <setting id="Channel_3_changed" value="False" />
    I would like to get every item where the number in the "id" field is similar, into a single array. What is the best way for me to do this? Thanks

  2. #2
    Sencha User slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    6,165

    Default

    It looks like you're iterating over the store and in the looping function you're evaluating the id value there in your current code. What part are you having trouble with?

  3. #3

    Default

    I would like to be able to combine all records in the array where the number is equal, into its' own array.

  4. #4
    Sencha User slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    6,165

    Default

    So, in your dataset you may have records with identical IDs? Is that correct?

  5. #5

    Default

    Kind of. I know this isn't ideal, but I am working with an existing application, and I cannot change how the data comes out of it.

  6. #6
    Sencha User slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    6,165

    Default

    I see. Duplicate IDs are treated rather permissively in Ext3, but that's not the case in 4 and 5. If they're not duplicated then... all's well.

    Code:
    var copiedRecs = [];
    settings.each(function(record) {
        var channel_id = record.get('id');
        channel_id = channel_id.split("_");
        record.set('number', channel_id[1]);
      
      if (.. your id matching logic here ..) {
      	copiedRecs.push(record.copy());
      }
    });
    
    
    // copiedRecs will be a copy of the records matching ID's
    // - or whatever eval logic you're using to determine that they belong in the separate array

  7. #7

    Default

    I appreciate your help so far. I am trying to figure out how to dynamically shift matching items into their own sub-arrays of the copiedRecs array. For example,
    Code:
    { {channel_num = 101 { id ='Channel_101_1' value='Nintendo' number='101'}{ id='Channel_101_2' value='1' number='101'} }
    Etc.

    As everything with a number='101' is an attribute of channel='101'

    Thanks again

Tags for this Thread

Posting Permissions

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