peter9477

Populate Cascades DropDowns from template

Jan 4th, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. import bb.cascades 1.0
  2.  
  3. Page {
  4. titleBar: TitleBar {
  5. title: root.activeTab.title
  6. }
  7.  
  8. Container {
  9. DropDown {
  10. id: first
  11. title : "First"
  12.  
  13. onCreationCompleted: {
  14. populateDropDown(first, template);
  15. print('DropDown', title, count(), template.count());
  16. }
  17. }
  18.  
  19. DropDown {
  20. id: second
  21. title : "Second"
  22.  
  23. onCreationCompleted: {
  24. populateDropDown(second, template);
  25. print('DropDown', title, count());
  26. }
  27. }
  28. }
  29.  
  30. attachedObjects: [
  31. DropDown {
  32. id: template
  33. title : "Template"
  34.  
  35. Option {
  36. text : "One"
  37. value : 1
  38. }
  39.  
  40. Option {
  41. text : "Two"
  42. value : 2
  43. selected : true
  44. }
  45.  
  46. Option {
  47. text : "Three"
  48. value : 3
  49. }
  50.  
  51. onCreationCompleted: {
  52. print('DropDown', title, count());
  53. }
  54. },
  55. ComponentDefinition {
  56. id: optionTemplate
  57. Option {
  58. }
  59. }
  60. ]
  61.  
  62. function populateDropDown(dropdown, template) {
  63. for (var i = 0; i < template.count(); i++) {
  64. var source = template.at(i);
  65. var option = optionTemplate.createObject();
  66. option.text = source.text;
  67. option.value = source.value;
  68. option.selected = source.selected;
  69. // etc, as required
  70. dropdown.add(option);
  71. }
  72. }
  73.  
  74. onCreationCompleted: {
  75. print('Page', template.count());
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment