我是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; } });
更多推荐
发布评论