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>
但是,我没有得到预期的活动/否课程。sectionContainer
嵌套在另一个模板中,如果这很重要的话。我觉得我在这里遗漏了一些非常简单的东西,我做错了什么?
使用不推荐使用的语法它工作得很好:
Template.sectionContainer.isActive = function() {
return (Session.get("activeSection") === 'start') ? "active" : "nope";
}
即使Template.sectionContainer.helpers.isActive()
从控制台运行也会返回正确的值。