Advertisement
Guest User

Table Data

a guest
Jan 9th, 2016
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var tableData = {
  2.     data: [
  3.         {
  4.             'name': 'Gary Finch',
  5.             'jobtitle': 'Front End Technical Lead',
  6.             'website': 'http://website.com'
  7.         },
  8.         {
  9.             'name': 'Bob McFray',
  10.             'jobtitle': 'Photographer',
  11.             'website': 'http://goo.gle'
  12.         },
  13.         {
  14.             'name': "Jenny O'Sullivan",
  15.             'jobtitle': 'LEGO Geek',
  16.             'website': 'http://stackoverflow.com'
  17.         }]
  18. }
  19.  
  20. var app = app || {};
  21.  
  22. app.table = (function () {
  23.     function Table(selector, data) {
  24.         this.selector = selector;
  25.         this.data = data;
  26.     }
  27.        
  28.         Table.prototype.buildTable = function () {
  29.             var tableRow;
  30.            
  31.             $.get('templates/tableDataTemplate.html', function (template) {
  32.             tableData.data.forEach(function (obj) {
  33.                 tableRow = Mustache.render(template, obj);
  34.                 $(this.selector).append(tableRow);
  35.             })
  36.         })
  37.         }    
  38.  
  39.     return {
  40.         load: function (selector, data) {
  41.             return new Table(selector, data);
  42.         }
  43.     }
  44. })();
  45.  
  46. var table = app.table.load('tbody', tableData);
  47.  
  48. table.buildTable();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement