Meteor 为什么要在排序列表中的每个项目之后添加新项目
我在服务器端有一个按时间排序的发布服务器,在客户端有一个项目列表。服务器向集合中添加新项后,客户端将此项添加到其他项之后Meteor 为什么要在排序列表中的每个项目之后添加新项目,meteor,meteor-blaze,Meteor,Meteor Blaze,我在服务器端有一个按时间排序的发布服务器,在客户端有一个项目列表。服务器向集合中添加新项后,客户端将此项添加到其他项之后 <body> {{> items}} </body> <template name="items"> <ul> {{#each items}} {{> item }} {{/each}} </ul> </template> <
<body>
{{> items}}
</body>
<template name="items">
<ul>
{{#each items}}
{{> item }}
{{/each}}
</ul>
</template>
<template name="item">
<li>{{time}}</li>
</template>
客户:
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()})
})
});
我的例子是可能重复的感谢,是的。很好的解决方案。
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()})
})
});