【发布时间】:2014-05-02 16:25:15
【问题描述】:
我被困在如何正确地将布尔模板帮助器设置为 true 仅用于一个项目并将其传递给模板。我该怎么做?
我正在尝试将许多文章之一设置为 true,以显示有关该文章的一些附加信息。我可能在一个模板中有 100 篇文章。我想在该特定模板上触发 mouseover 布尔值,然后在 mouseover 上设置一个布尔值为 true 的帮助器以触发其他 html 的显示。
mouseover 已关闭:
'mouseover .hover-check': function () {
console.log('hover-check works for *one* particular item');
// need to set boolean here - tried the below code
Session.set('showHover', true); // Tried various versions of this...
}
对于上述内容,我还尝试了以下内容:
this.hover
Session.set('this.hover');
和
Session.set('this.hover', true);
但没有正确地把它放到模板中。它确实正确地得到了一篇文章。因此,似乎正确设置变量并将其放入模板是我的麻烦所在。
我还有一个帮手:
Template.articleItem.helper({
showHover: function () {
//Where I need help. I've tried:
return showHover; //Sets hoverCheck to true for each of 100 articles but I only want the hovered one to have hoverCheck as true
}
});
还有一个问题是如何将showHover === true 发送到模板。我尝试了各种方法,例如:
{{showHover}} docs say to call it 似乎是这样的(尽管他们没有显示如何关闭它)。还有{{#if showHover}}
【问题讨论】:
标签: jquery templates event-handling meteor view-helpers