流星辅助功能在使用'findOne'时会重新运行几次



假设我有一个名为Books:的集合

{
 title : "string",
 author : "string"
}

让我们看看以下代码:

Template.bookList.helpers({
    books: function() {
      console.log('meteor');
      return Posts.find();
    }
});

在这种情况下,"流星"将被打印一次。但如果我像这样使用findOne

Template.bookItem.helpers({
    book: function() {
      console.log('meteor');
      return Posts.findOne({'title':'title of the book'});
    }
});

"流星"将被打印几次(在某些情况下,大约六分之二)。

为什么!?

是否应该使用{{#with}}来触发函数?有时{{#if}}无法在预期下工作

最新更新