在 Meteorjs 中滚动到底部

Scroll to the bottom in Meteorjs

我有一个列表模板,如下所示:

{{#each item}}
  {{ this }}
{{/each}}

该助手中的项目是一个数据库游标,如下所示:

Items.find({ group: Session('group') });

因此,当组更改时,模板会重新呈现。我希望每次模板重新呈现时都将模板滚动到底部,因为项目列表发生变化。我使用 el.scrollTop = el.scrollHeight; 滚动到底部,此代码位于呈现的回调中。但是当模板 重新呈现 时,回调不会被触发。无论如何都要这样做?

我建议查看 Template.autorun,它可以在创建或渲染中使用。关键是对反应性集合的赋值,在本例中是 Session 对象。

Template.myTemplate.rendered = function(){
    this.autorun(function(){
        var group = Session.get("group");
        // rest of code here
    });
});

流星文档:http://docs.meteor.com/#/full/template_autorun