Meteor 流星助手返回一个可用类

Meteor 流星助手返回一个可用类,meteor,meteor-helper,Meteor,Meteor Helper,Meteor noob在这里,试图掌握模板的窍门。因此,我在JS中设置了以下内容: Session.set('activeSection', 'start'); Template.sectionContainer.helpers = ({ "isActive": function() { return (Session.get("activeSection") === 'start') ? "active" : "nope"; } }); 然后有: <t

Meteor noob在这里,试图掌握模板的窍门。因此,我在JS中设置了以下内容:

Session.set('activeSection', 'start');

Template.sectionContainer.helpers = ({
    "isActive": function() {
        return (Session.get("activeSection") === 'start') ? "active" : "nope";
    }
});
然后有:

<template name="sectionContainer">
    <section class="{{isActive}}"></section>
</template>

即使从控制台运行
Template.sectionContainer.helpers.isActive()
,也会返回正确的值。

您应该像这样使用它:

Template.sectionContainer.helpers({
    isActive: function() {
        return Session.equals("activeSection", "start") ? "active" : "nope";
    }
});
如果有效:

Template.sectionContainer.isActive = function() {
   return (Session.get("activeSection") === 'start') ? "active" : "nope";
}
然后,在新语法中,它将是:

Template.sectionContainer.helpers({
    isActive: function() {
        return (Session.get("activeSection") === 'start') ? "active" : "nope";
    }
});

谢谢这当然是一个更好的条件语法,但不能解决我的渲染问题,不幸的是。嗯,你有没有类似的东西:??不在同一个文件中。我用。。。(在它自己的HTML文件中)在另一个类似这样的文件中:显然我当时把语法记下来了,但我一定是做错了什么,因为一个简单的旧语法转换->新语法正在破坏代码。isActive:function(){if(Session.get(“activeSection”)=“start”)返回“active”;返回“nope”}如果这不起作用,那么sessionIt就有问题,它不起作用。在控制台中运行“Session.get(“activeSection”)”会显示正确的值:/可能您已将此帮助程序签名到另一个模板,而不是在-template..helpers中使用它。然后我不会把它推到某个存储库,我会看看可能是什么问题
Template.sectionContainer.helpers({
    isActive: function() {
        return (Session.get("activeSection") === 'start') ? "active" : "nope";
    }
});