Sencha Touch - Accessing Associated-Model Store JSON via Nested Looping -


i've been lurking on stack overflow quite time now, , have found quite number of helpful answers. many community! hope able contribute own helpful answers before long.

in meantime, have issue can't figure out. using sencha touch create web-based phone app , i'm having trouble using nested loop iterate through json. can grab first level of data, not items nested within first level. there related extjs thread, decided create own since extjs , touch diverge in subtle yet important ways. anyway, here code show am:

json (truncated - json php/mysql-generated, , there 3 sub levels "title", of can access. it's sub level "items" through can't iterate):

{ "lists": [     {         "title": "groceries",         "id": "1",         "items": [             {                 "text": "contact solution - coupon",                 "listid": "1",                 "id": "4",                 "leaf": "true"              },             {                 "text": "falafel (bulk)",                 "listid": "1",                 "id": "161",                 "leaf": "true"              },             {                 "text": "brita filters",                 "listid": "1",                 "id": "166",                 "leaf": "true"              }         ]      }  ] 

}

store:

var storeitms = new ext.data.store({     model: 'lists',     proxy: {         type: 'ajax',         method: 'post',         url : list_src,         extraparams: {action: 'gtlstitms'},         reader: {             type: 'json',             root: 'lists'         }     } }); 

working loop:

storeitms.on('load', function(){     var lstarr = new array();     storeitms.each(function(i) {         var title = i.data.title;         lstarr.push(i.data.title);     });     console.log(lstarr); }); 

non-working nested loop:

storeitms.on('load', function(){     var lstarr = new array();     storeitms.each(function(i) {         var title = i.data.title;         var id = i.data.id;         title.items.each(function(l) {             lstarr.push(l.data.text);         });     });     console.log(lstarr); }); 

the non-working nested loop gives me error "cannot call method 'each' of undefined", in reference 'title.items.each...'

i suspect because i've not set title key set key:value pair, sees list of strings...but i'm kind of @ loss.

i should mention store populated via 2 models have been associated 1 another. know store can access because able nested iterating via xtemplate.

any appreciated , returned community in kind before long!'

-eric

eric, why loop?

if models associated in same way json nested, should able set autoload:true on store, sit , enjoy.

anyway, on assumption needing these arrays other unrelated reason, problem trying .each on

i.data.title.items 

surely should iterating through

i.data.items 

also, if object model, can use .get() instead of data object:

var title = i.get('title); 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -