流星列表项目计数(Meteor List item count)

编程入门 行业动态 更新时间:2024-10-26 18:24:21
流星列表项目计数(Meteor List item count)

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

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

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

我想知道我是否走在正确的道路上,或者是否有人建议如何实现这一目标。

I am fairly new to Meteor and MongoDB. I am simply trying to print a task list to a table and would like to grab the order of each task in the DB. If a task is deleted then it would be reordered. I know this may be a two part question.

I have been able to grab the total number of items in the collection using:

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

I am wondering if I am on the right path or if someone has a suggestion about how this could be accomplished.

最满意答案

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

.html文件

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

.js文件

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

There's a @index helper function built into Blaze that returns the zero based index for the current item:

.html file

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

.js file

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

更多推荐

本文发布于:2023-08-07 14:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464719.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:流星   项目   列表   Meteor   item

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!