PDA

View Full Version : How to loop through an array in a store using tpl?



FlaminPhoenix
25 May 2010, 8:25 PM
The scenario is like this:

I have an array which has a child array:

parent array
L child array

Both parent, and child arrays are flat arrays, not associative. Im loading the parent array into a store. Now, I want to use a tpl for my rowexpander. Im able to access the stores elements by using {name_of_element_in_store} syntax. Now the problem is Im unable to access the child array here.. As all examples for looping with templates involve using associative arrays, Id like to get a pointer or two from you guys on how to do the following with a flat array:

'<tpl for={Sources}>',
'<div>{.}</div>',
'</tpl>'

Sources is the corresponding name in the datastore. This element supposedly holds the child array. Any and all help will be greatly appreciated..Thanks in advance:s

Condor
25 May 2010, 10:57 PM
It's:

'<tpl for="Sources">',
'<div>{.}</div>',
'</tpl>'

FlaminPhoenix
25 May 2010, 11:25 PM
It's:

'<tpl for="Sources">',
'<div>{.}</div>',
'</tpl>'

I get an error saying Expected ')'. Just to make things clearer, the following is my code:


for (var i=0;i<count;i++)
{
childArr = new Array();
childArr.push("blank");
childArr.push("blank");
childArr.push("blank");
childArr.push("blank");
childArr.push("blank");
childArr.push("blank");
childArr.push("blank");
childArr.push("blank");
childArr.push("blank");
childArr.push("blank");
childArr.push("blank");
childArr.push("blank");
childArr.push("blank");
childArr.push("blank");
childArr.push("blank");
var sourceArr = new Array();
for (var j=0;j<10;j++)
{
sourceArr.push(j);
}
childArr.push(sourceArr);
myData.push(childArr);
}



var store = new Ext.data.ArrayStore({
id: 'configGridStore',
fields: [
{ name: 'dataProfiles' },
{ name: 'dataProfileID' },
{ name: 'status' },
{ name: 'totalNoOfSrcObjects', type: 'string' },
{ name: 'totalNoOfObjectsProcessed', type: 'string' },
{ name: 'noOfObjectsBeingProcessed', type: 'string' },
{ name: 'noOfObjectsFailed', type: 'string' },
{ name: 'avgProcessingTimePerObject', type: 'string' },
{ name: 'startDateTime', type: 'string' },
{ name: 'estimatedEndDateTime', type: 'string' },
{ name: 'controls', type: 'string' },
{ name: 'source', type: 'string' },
{ name: 'destination', type: 'string' },
{ name: 'noOfThreads', type: 'string' },
{ name: 'noOfObjectsPerThread', type: 'string' },
{name:'DPSources'}
]
});

store.loadData(myData);



The template is for a rowexpander:

tpl: new Ext.Template(
'<div id="div'+(globalIDCounter++)+'"><br><p><b>Source:</b> {source}</p>',
'<br>',
'<p><b>No Of Threads:</b> {noOfThreads}</p>',
'<br>',
'<p><b>No Of Objects Per Thread:</b> {noOfObjectsPerThread}</p>',
'<br>',
'<p><b>Destination:</b> {destination}</p>',
'<br>',
'<tpl for="DPSources">',
'<div>{.}</div>',
'</tpl>'
'<input type="button" value="Start Crawling" onclick="handleStartCrawling({dataProfileID});"></input></div>'
)

Condor
26 May 2010, 12:21 AM
You are missing a comma:

'</tpl>',

FlaminPhoenix
26 May 2010, 2:36 AM
cant believe I made such a stupid mistake... thank you for your help condor.. much appreaciated..

mperalta
20 Nov 2012, 12:22 AM
I have this data

{

"total":2,
"rows":[
{

"customer_group_id":"1",
"customer_group_name":"Italian Restaurant",
"sales":[
{

"item_group_name":"Artichoke",
"current_month_revenue":"50",
"previous_months_revenue_avg":85
},
{

"item_group_name":"Capers",
"current_month_revenue":"30",
"previous_months_revenue_avg":78
}
]
},
{

"customer_group_id":"2",
"customer_group_name":"Western Restaurant",
"sales":[
{

"item_group_name":"Artichoke",
"current_month_revenue":"150",
"previous_months_revenue_avg":61
},
{

"item_group_name":"Capers",
"current_month_revenue":"208",
"previous_months_revenue_avg":111
}
]
}
]
}

I want to build an matrix table data view like
Artichoke Capers
Italian Restaurant 50 100

Any help would be appreciated.

Thanks.
Mike