【问题标题】:Meteor List item count流星列表项目计数
【发布时间】:2016-11-27 22:09:05
【问题描述】:

我对 Meteor 和 MongoDB 还很陌生。我只是想将任务列表打印到表中,并想获取数据库中每个任务的顺序。如果一个任务被删除,那么它将被重新排序。我知道这可能是一个两部分的问题。

我已经能够使用以下方法获取集合中的项目总数:

Template.task.helpers({
  taskCount() {
    return Tasks.find().count(this._id)
  }
});

我想知道我是否走在正确的道路上,或者是否有人对如何实现这一点提出了建议。

【问题讨论】:

    标签: javascript mongodb meteor meteor-blaze


    【解决方案1】:

    Blaze 中内置了一个 @index 辅助函数,它返回当前项的从零开始的索引:

    .html 文件

    <ul>
    {{#each tasks}}
        <li>{{plus1 @index}}. {{title}}</li>
    {{/each}}
    </ul>
    

    .js 文件

    Template.task.helpers({
      plus1(index) {
        return index + 1;
      }
    });
    

    【讨论】:

    • 漂亮!我知道这一定是非常简单的事情(就像 Meteor 一样!)
    猜你喜欢
    • 2015-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多