How to refresh template


#1

Dears,

I would like to refresh the orders where its content is coming from REST API. How new orders will be updated without page refresh, in case new orders coming from the REST API? Is there any code sample?

<table id="orders" cellspacing="0" cellpadding="0">
    <thead>
      <tr>
        <th><span>Time</span></th>
        <th><span>Total</span></th>
        <th><span>Type</span></th>
      </tr>
    </thead>
    <tbody>
      {{#each orders}}
      <tr>
        <td>{{time}}</td>
        <td>{{total}}</td>
        <td>{{type}}</td>
      </tr>
      {{/each}}
    </tbody>
  </table>

.js

I will update this code to fetch REST API.

Template.body.helpers({
orders: [
{ time: “1428244334180”,id: 1000, total: 10, type: “Delivery”, status: 1, sla: 45 },
{ time: “1428244347017”,id: 1001, total: 15, type: “Collection”, status: 2, sla: 30 }
],

Thx


#2
ClientPosts = new Mongo.Collection 'posts', connection: null

HTTP.get '/api/get/posts/', {}, (err, res) ->
    ClientPosts._collection.pauseObservers()
    ClientPosts.remove {}, ->
        _.each res.data.posts, (newPostData) ->
            ClientPosts.insert newPostData
    ClientPosts._collection.resumeObservers()

Template.body.helpers
    posts: ->
        ClientPosts.find({})

#3

@mrzafod I think the first line can be simplified to:

ClientPosts = new Mongo.Collection

#4

@sashko Triple Yes! I forgot, thanks.