【发布时间】:2013-11-18 09:06:51
【问题描述】:
我试图让一些非常基本的东西在 Meteor 中工作,当用户单击按钮时,会调用 Session.set(),然后显示 div。问题是,如果我不调用 Session.set() ,则行为与单击按钮时显示 div 的预期一样。但是一旦我包含 Session.set() 我需要在消息实际显示之前单击两次。为确保可以重现该行为,请确保页面是干净的加载而不是 Meteor 刷新! HTML的代码是:
<head>
<title>test</title>
</head>
<body>
{{> home}}
</body>
<template name="home">
<div>
<input type="button" id="addButton" value="add">
</div>
{{> popup}}
</template>
<template name="popup">
{{#with messageHelper}}
<div id="messageDiv" style="display: none">
message is {{message}}
</div>
{{/with}}
</template>
这是让它运行的 Javascript。
Template.home.events({
'click #addButton': function(){
// **** if this line is commented out, it will work
Session.set("messageHelper", {message: 'HERE'});
// ****
$('#messageDiv').show();
}
});
Template.popup.helpers({
messageHelper: function(){
return Session.get("messageHelper");
}
});
【问题讨论】:
标签: javascript jquery session meteor