Creating subpages in a tableview from JSONfile ???
Hello;
I've succeeded in parsing a JSON to populate a tableview, but i was wondering if it's possible to make the rows of the 'JSON-populated' tableview 'clickable' to open a new json-populated tableview
(for instance: Animals (Dogs - Cats - Birds) and when 'Dogs' is clicked a new tableview opens with all the dogs
(hope i made myself a bit clear)
Kind Regards;
2 Answers
-
here is some code I wrote that has a two level deep navigation for iOS
you have already solved the parsing of the JSON and the table creation so you should be all set. I would suggest storing some value in each row so on the "click" event you can retrieve the appropriate JSON data for rendering the detailed table view
-
data = [ { title: 'dogs', hasChild: true, names: [ { title: 'fluffy' }, { title: 'blackie' }, { title: 'noisy' } ] }, { title: 'cats', hasChild: true, names: [ { title: 'lazy' }, { title: 'sleepy' }, { title: 'hungry' } ] } ]; tv = Ti.UI.createTableView({data: data}); Ti.UI.currentWindow.add(tv); tv.addEventListener('click', function(e) { if(e.rowData.names) { var newWin = Ti.UI.createWindow({title: e.rowData.title}); var newTv = Ti.UI.createTableView({data: e.rowData.names}); newWin.add(newTv); newWin.open(); } });
PS: did not test the code…