【发布时间】:2015-01-08 13:03:07
【问题描述】:
在下面的代码中,当我单击按钮时,我期望 {{#if adding_answers}} 会话变量为 true。它会触发"click .setup_answers':function",但模板{{> newAnswers}} 永远不会显示,因为{{#if adding_answers}} 这不是真的。我看到它通过console.log 设置为true,但是当它返回HTML 时什么也没有。
我认为通过将其设置为流星反应会导致它被看到的值?
HTML 代码
<template name="newQuestions">
{{#if adding_answers}} <!-- Session Variable -->
{{> newAnswers}}
{{/if}}
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Questions</h3>
<p></p>
<form class="form-horizontal">
<div class="form-group">
<label class="sr-only" for="inputQuestion">Question</label>
<input type="textarea" class="form-control" name="inputQuestion" id="inputQuestion" autofocus="1" placeholder="Enter New Question" rows="5">
</div>
<button type="button" class="setup_answers btn-primary">Setup Answers</button>
</form>
</div>
</div>
</template>`
JS 代码
`Template.newQuestions.events({
"click .archive": function(event, template){
return Meteor.call('archiveTodo',this._id,!this.archived);
},
'click .todochecked':function(event,template){
return Meteor.call('completeTodo',this._id,!this.completed);
},
'click .setup_answers':function(event,template){
var question = $('#inputQuestion').val(); // Question must be entered.
if (question === "") {
alert("The question can not be blank.");
Session.set('adding_answers',false);
} else {
Session.set('adding_answers',true); // Causes template newAnswers to be displayed
}
return session.get('adding_answers');
}
});`
【问题讨论】:
标签: javascript meteor