流星删除自动运行中的火焰模板

Meteor remove blaze template in autorun

本文关键字:火焰 运行 删除 流星      更新时间:2023-09-26

我有一个加载模板。每当客户端从服务器订阅数据时,都需要加载CCD_ 1。

Template.myTemplate.onCreated(function() {
    var loading;
    Template.instance().autorun(function() {
         if (!Template.instance().subscriptionsReady()) {
           loading = Blaze.render(Template.loading, document.getElementsByTagName('body')[0]);
         } else {
           Blaze.remove(loading);
         }
    });
});

第1次CCD_ 2和CCD_。但如果我做更多的订阅,它会继续添加loading模板。当其他部分执行时,如何从DOM中删除模板?

if (!Template.instance().subscriptionsReady()) {
    if (Template.loading.isRendered) {
        return;
    }
    // if not rendered to DOM, then do render
} else {
    Blaze.remove(loading);
}