templates.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. Ext.require('widget.panel');
  2. Ext.onReady(function(){
  3. var data = {
  4. name: 'Abe Elias',
  5. company: 'Sencha Inc',
  6. address: '525 University Ave',
  7. city: 'Palo Alto',
  8. state: 'California',
  9. zip: '44102',
  10. kids: [{
  11. name: 'Solomon',
  12. age:3
  13. },{
  14. name: 'Rebecca',
  15. age:2
  16. },{
  17. name: 'Rebecca 1',
  18. age:0
  19. }]
  20. };
  21. Ext.create('Ext.Panel', {
  22. width: 300,
  23. renderTo: 'template-example',
  24. style: "margin:15px",
  25. bodyStyle: "padding:5px;font-size:11px;",
  26. title: 'Basic Template',
  27. tbar: [{
  28. text: 'Apply Template',
  29. listeners: {
  30. click: function() {
  31. var panel = this.up("panel"),
  32. tpl = Ext.create('Ext.Template',
  33. '<p>Name: {name}</p>',
  34. '<p>Company: {company}</p>',
  35. '<p>Location: {city}, {state}</p>'
  36. );
  37. tpl.overwrite(panel.body, data);
  38. panel.doComponentLayout();
  39. }
  40. }
  41. }],
  42. html: '<p><i>Apply the template to see results here</i></p>'
  43. });
  44. Ext.create('Ext.Panel', {
  45. width: 300,
  46. renderTo: 'xtemplate-example',
  47. style: "margin:15px",
  48. bodyStyle: "padding:5px;font-size:11px;",
  49. title: 'XTemplate',
  50. tbar: [{
  51. text: 'Apply Template',
  52. listeners: {
  53. click: function() {
  54. var panel = this.up('panel'),
  55. tpl =Ext.create('Ext.XTemplate',
  56. '<p>Name: {name}</p>',
  57. '<p>Company: {company}</p>',
  58. '<p>Location: {city}, {state}</p>',
  59. '<p>Kids: ',
  60. '<tpl for="kids" if="age &eq;%eq; \'Abe Elias\'>',
  61. '<tpl if="age &gt; 1"><p>{#}. {parent.name}\'s kid - {name}</p></tpl>',
  62. '</tpl></p>'
  63. );
  64. tpl.overwrite(panel.body, data);
  65. panel.doComponentLayout();
  66. }
  67. }
  68. }],
  69. html: '<p><i>Apply the template to see results here</i></p>'
  70. });
  71. });