为什么新项目在排序列表中的每个项目后添加

时间:2014-11-30 16:19:18

标签: meteor meteor-blaze

我在服务器端按时间排序的发布者和客户端上的项目列表。在服务器向集合添加新项目之后,客户端将此项目添加到其他项目之后。

<body>
  {{> items}}
</body>

<template name="items">
    <ul>
      {{#each items}}
        {{> item }}
      {{/each}}
    </ul>
</template>

<template name="item">
  <li>{{time}}</li>
</template>

普通的:

Items = new Mongo.Collection("items");

客户端:

Meteor.subscribe('items')

Template.items.helpers({
  items: function() {
    return Items.find()
  }
})

Template.item.helpers({
  time: function() {
    return this.time.toString()
  }
})

服务器:

Meteor.publish('items', function() {
  return Items.find({}, {sort: {time: -1}})
})

Meteor.startup(function () {
    var CronManager = new Cron(1000)

    CronManager.addJob(5, function() {
      Items.insert({time: new Date()})  
    })
});

我在meteorpad

上的例子

0 个答案:

没有答案
相关问题