1. #1
    Sencha User FlaminPhoenix's Avatar
    Join Date
    May 2009
    Posts
    146
    Vote Rating
    0
    FlaminPhoenix is on a distinguished road

      0  

    Exclamation How to loop through an array in a store using tpl?

    How to loop through an array in a store using tpl?


    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
    No one stands taller than the last man standing

  2. #2
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    96
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    It's:
    Code:
    '<tpl for="Sources">',
    '<div>{.}</div>',
    '</tpl>'

  3. #3
    Sencha User FlaminPhoenix's Avatar
    Join Date
    May 2009
    Posts
    146
    Vote Rating
    0
    FlaminPhoenix is on a distinguished road

      0  

    Default


    Quote Originally Posted by Condor View Post
    It's:
    Code:
    '<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>'
    )
    No one stands taller than the last man standing

  4. #4
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    96
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    You are missing a comma:
    Code:
    '</tpl>',

  5. #5
    Sencha User FlaminPhoenix's Avatar
    Join Date
    May 2009
    Posts
    146
    Vote Rating
    0
    FlaminPhoenix is on a distinguished road

      0  

    Default


    cant believe I made such a stupid mistake... thank you for your help condor.. much appreaciated..
    No one stands taller than the last man standing

  6. #6
    Sencha User
    Join Date
    Dec 2011
    Posts
    3
    Vote Rating
    0
    mperalta is on a distinguished road

      0  

    Default tpl dataview problem

    tpl dataview problem


    I have this data

    {
    • "total":2,
    • "rows":[
      1. {
        • "customer_group_id":"1",
        • "customer_group_name":"Italian Restaurant",
        • "sales":[
          1. {
            • "item_group_name":"Artichoke",
            • "current_month_revenue":"50",
            • "previous_months_revenue_avg":85
            },
          2. {
            • "item_group_name":"Capers",
            • "current_month_revenue":"30",
            • "previous_months_revenue_avg":78
            }
          ]
        },
      2. {
        • "customer_group_id":"2",
        • "customer_group_name":"Western Restaurant",
        • "sales":[
          1. {
            • "item_group_name":"Artichoke",
            • "current_month_revenue":"150",
            • "previous_months_revenue_avg":61
            },
          2. {
            • "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

Similar Threads

  1. Replies: 4
    Last Post: 1 Jul 2009, 8:52 AM
  2. Replies: 6
    Last Post: 1 Apr 2009, 8:12 AM
  3. Array.sortDates ,Array.unique, and extended Array.indexOf
    By wm003 in forum Ext 2.x: User Extensions and Plugins
    Replies: 3
    Last Post: 4 May 2008, 12:38 AM

Thread Participants: 2