简体   繁体   English

流星:如何通过表滚动数据?

[英]Meteor: How do you roll data thru a table?

If I'm doing a find() and returning the last five records why aren't all five records updated when {{# each}} is updated? 如果我正在执行find()并返回最后五个记录,为什么在更新{{# each}}时不更新所有五个记录? Isn't the find() triggered to return the last 5 records? 是否触发了find()以返回最后5条记录?

Basically, I'm just trying to roll my data through the table as an item is added, so if items 1 thru 5 displayed in the table and you add an item, the table will display item 2 thru 6. 基本上,我只是想在添加项目时在表中滚动数据,因此,如果表中显示项目1至5并添加项目,则表将显示项目2至6。

You can use 'limit' and 'sort' ( docs ): 您可以使用'limit'和'sort'( docs ):

{{#each something}}
    <tr>
      ....
    </tr>
{{/each}}

Then your find, make sure you specify 'sort' since you need to tell meteor how it needs to 'roll' them, ie by date? 然后您的发现,确保您指定“ sort”,因为您需要告诉流星它如何“滚动”它们,即按日期? (this example assumes you have a date field): (此示例假定您有一个date字段):

Template.yourtemplate.helpers({
    something: function() {
        return YourCollection.find({}, {limit: 5, sort:{date:-1}})
    }
});

The -1 is the sorting order, the higher (or later) dates come up at the top, if you use 1 the earliest come up at the top. -1是排序顺序,较高(或较晚)的日期在顶部,如果您使用1则最早出现在顶部。

I actually ended up using Justin McCandless' answer from this thread where the sort wasn't working at all. 实际上,我最终从这个线程根本无法使用的线程中使用了Justin McCandless的答案。

Meteor.js: Find all documents and return in reverse natural order Meteor.js:查找所有文档并以自然相反的顺序返回

return WeighIn.find({}, {sort:{weight: -1}, limit:5}).fetch().reverse();

Adding the reverse() made the table behave the way I needed it to. 添加reverse()可使表按照我需要的方式运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM