如果集合在MeteorJS中为null或不为null,则显示模板

Display template if collection is null or not in MeteorJS

本文关键字:null 显示 集合 MeteorJS 中为 如果      更新时间:2023-09-26

我不确定这在metrojs中是否可能,我有两个模板——"register"answers"login"。我想把一个条件放在哪里:

如果集合为空显示寄存器模板

如果没有,则显示登录模板。

请告知。非常感谢。

您可以使用助手函数。

HTML:

<template name="main">
    {{#if collectionHasItems}}
        {{> login}}
    {{else}}
        {{> register}}
    {{/if}}
</template>
<template name="register">
    // More code here
</template>
<template name="login">
    // More code here
</template>

JS:

Template.main.helpers({
    collectionHasItems: function() {
        return Collection.find().count();
    }
});