T1000
T1000

Reputation: 2941

Ext.XTemplate loop through object

my controller returns data like this:

{
   "success":true,
   "data":{
      "35":{
         "msg":{
            "32":{
               "module_id":"35",
               "alert_id":"32",
               "alert_datetime":"2012-11-28 16:19:19",
               "param1_type":"imo",
               "param1_value":"453465",
               "param2_type":"",
               "param2_value":"0",
               "param3_type":"",
               "param3_value":"0",
               "msg":"triiiis dve",
               "count":1
            },
            "33":{
               "module_id":"35",
               "alert_id":"33",
               "alert_datetime":"2012-10-28 00:00:00",
               "param1_type":"imo",
               "param1_value":"54984",
               "param2_type":"",
               "param2_value":"0",
               "param3_type":"",
               "param3_value":"0",
               "msg":"triis tri",
               "count":1
            }
         }
      },
      "42":{
         "msg":{
            "1":{
               "module_id":"42",
               "alert_id":"1",
               "alert_datetime":"2012-10-28 16:19:19",
               "param1_type":"imo",
               "param1_value":"9281906",
               "param2_type":"",
               "param2_value":"0",
               "param3_type":"",
               "param3_value":"0",
               "msg":"",
               "count":1
            }
         }
      },
      "39":{
         "msg":{
            "2":{
               "module_id":"39",
               "alert_id":"2",
               "alert_datetime":"2012-10-28 12:36:31",
               "param1_type":"imo",
               "param1_value":"65464546",
               "param2_type":"",
               "param2_value":"0",
               "param3_type":"",
               "param3_value":"0",
               "msg":"",
               "count":1
            }
         }
      }
   }
}

After that I do this

that.tpl.overwrite(that.el, Ext.decode(response).data);

The problem is that I can't loop through the result object keys... I know how to loop through objects with pre-defined key names, but mine are dynamicaly generated...
Will appreciate some help, thanks!

Upvotes: 0

Views: 2057

Answers (1)

smhg
smhg

Reputation: 2198

I am assuming you have an idea of the depth of nesting (4 levels below the "data" element in this case):

You could loop through the data with Ext.Object.each (maybe there are some query methods for this too, not sure), looping through each element's children too. In case you use Ext.data.Model instances, you can use the Ext.data.association links to loop through the data.

In that case you could make a different template for each level and insert the result of each template in the template of the level above.

It sounds more difficult than it actually is I think.

foreach in templates is currently indeed only available for support subscribers.

Upvotes: 1

Related Questions