nubilfi

express dom rendered object

Jan 16th, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. routes/item.js
  2. ------------------------------------------------
  3. /* GET items listing */
  4.     router.get('/', function(req, res, next) {
  5.         Item.find({}, function(err, item) {
  6.             if (err) {
  7.                 return console.log(err);
  8.             }
  9.             res.render('item/index', item);
  10.         }).select('item_id item_name');
  11.     });
  12.  
  13. views/item/index.hbs
  14. -----------------------------------------------
  15. <div class="table-responsive no-padding" id="itemList">
  16.    <table class="table table-hover table-striped">
  17.        <thead>
  18.            <th>No.</th>
  19.            <th>Item ID</th>
  20.            <th>Item Name</th>
  21.        </thead>
  22.        <tbody>
  23.              <!-- populate table here -->
  24.        </tbody>
  25.    </table>
  26.  
  27.    <script type="text/javascript" src="/javascripts/global.js"></script>
  28. </div>
  29.  
  30. public/javascripts/global.js
  31. -----------------------------------------------
  32. // DOM Ready =================
  33. $(document).ready(function() {
  34.     // Populate table on initial page load
  35.     populateTable();
  36. });
  37.  
  38. function populateTable() {
  39.     $.ajax({
  40.         url: '/item',
  41.         type: 'GET',
  42.         success: function (item) {
  43.             console.log(item);
  44.         }
  45.     });
  46. }
Add Comment
Please, Sign In to add comment