Guest User

Untitled

a guest
Dec 10th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. function setTableData() {
  2. var db = Ti.Database.install('mm.sqlite', 'recipes');
  3. var rows = db.execute('select i.caption, i_s.orderID, i_s.sectionID, i_s.name ' + 'from recipes r ' + 'inner join instructions i on r.fcid = i.recipeID ' + 'inner join inst_sections i_s on i.timeID = i_s.sectionID ' + 'where fcid IN (' + chosenRecipes + ') ' + 'order by i_s.orderID ASC');
  4.  
  5. // create the array
  6. var dataArray = [];
  7. var tableData = [];
  8.  
  9. while(rows.isValidRow()) {
  10.  
  11. dataArray.push({
  12. title : '' + rows.fieldByName('caption') + '',
  13. section : '' + rows.fieldByName('name') + '',
  14. sortOrder : '' + rows.fieldByName('orderID') + '',
  15. hasChild : false
  16. });
  17. rows.next();
  18. };
  19.  
  20. var pre = '';
  21. for(var i = 0, j = dataArray.length; i < j; i++) {
  22. if(dataArray[i].section != pre)
  23. tableData[i] = Ti.UI.createTableViewSection({
  24. headerTitle : dataArray[i].section
  25. })
  26. pre = dataArray[i];
  27. var tvr = Ti.UI.createTableViewRow();
  28. tvr.height = 'auto';
  29. var tvrl = Ti.UI.createLabel({
  30. text: dataArray[i].title,
  31. left: 10,
  32. top: 10,
  33. bottom: 10,
  34. right: 10,
  35. height: 'auto'
  36. });
  37. tvr.add(tvrl);
  38. tableData[i].add(tvr);
  39.  
  40.  
  41. }
  42.  
  43. tv.data = tableData;
  44.  
  45. }
Add Comment
Please, Sign In to add comment