Javascript Meteor:更改单击事件的变量值

Javascript Meteor:更改单击事件的变量值,javascript,meteor,Javascript,Meteor,我只想显示所单击的日期的注释 以下是我的应用程序的结构: homePage.html <template name="homePage"> <h2>Welcome to home page!</h2> {{#each posts}} {{> postOnDay}} {{/each}} </template> <template name="postOnDay"> <a hre

我只想显示所单击的
日期的
注释

以下是我的应用程序的结构:
homePage.html

<template name="homePage">
    <h2>Welcome to home page!</h2>
    {{#each posts}}
        {{> postOnDay}}
    {{/each}}
</template>
<template name="postOnDay">
    <a href="#" class="aDay">{{day}}</a>
    <div style="display:{{showPost}}">
        {{note}}    
    </div>
</template>
postOnDay.js

Template.homePage.helpers({
   posts: function() {
        //alert(Posts.find().count());
        return Posts.find();
    }
});
Template.postOnDay.events({
    'click .aDay': function(e) {
        e.preventDefault();
        var link = e.currentTarget;
        showPost: 'inline' //change value on click
    }
});

Template.postOnDay.helpers({
    showPost: 'none' //default value
})

如果要更改帮助程序和事件处理程序中的值,应使用会话:

而不是

     showPost: 'inline' //change value on click
   }
});

Template.postOnDay.helpers({
    showPost: 'none' //default value
})
我会:

      Session.set('showPost', 'inline'); //change value on click
    }
});

Template.postOnDay.helpers({
    showPost: function(){ return Session.get('showPost')}
})
对于默认值,请使用:

Session.setDefault('showPost', 'inline')
这可以根据您的需要在模板或应用程序初始化中进行

另一件需要考虑的事情是,如果您希望每个帖子都有一个变量,那么您可能需要使用以下内容:

Session.get('showPost' + this.id)

请确保在控制台中输出
this
的值,这样您就可以确保this.id在每篇文章中都是唯一的。

您应该迭代几天而不是文章,不是吗?你想显示日历吗?@juanpstatas让我们假设我将
post
移动到另一个模板。然后,当我点击
day
时,我将如何显示/隐藏帖子模板?谢谢。我刚刚得到了你先前评论的回复。你能帮我吗?