View Full Version : Iterating from one ArrayStore to another based on values like

17 Nov 2014, 11:45 AM
I have a data store that looks like this:

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.on('load', function(store, recs, opt){
var channel_id = record.get('id');
channel_id = channel_id.split("_");
record.set('number', channel_id[1]);
}, this);

that is populated with this data:

<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

19 Nov 2014, 9:50 AM
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?

19 Nov 2014, 12:10 PM
I would like to be able to combine all records in the array where the number is equal, into its' own array.

19 Nov 2014, 12:47 PM
So, in your dataset you may have records with identical IDs? Is that correct?

20 Nov 2014, 5:04 AM
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.

20 Nov 2014, 9:11 AM
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.

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 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

21 Nov 2014, 9:28 AM
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,

{ {channel_num = 101 { id ='Channel_101_1' value='Nintendo' number='101'}{ id='Channel_101_2' value='1' number='101'} }


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

Thanks again