【发布时间】:2016-12-09 19:38:56
【问题描述】:
在一个流星应用程序中,我试图创建一个页面,如果你按下一个按钮,它会显示一个模板,然后如果你按下另一个按钮,它会隐藏相同的模板。我尝试使用两个带有监听器的按钮来实现这一点,它们将布尔值(称为切换)更改为真或假。辅助方法应将 true 或 false 的值返回给 if 语句,以便可以显示 anotherTemplate 但我收到此错误:
Uncaught ReferenceError: toggle is not defined at object.clickDataActionShow
似乎切换超出范围?或者完全不同的东西,我无法理解。
要提一提的是,自动发布功能已被删除,所以有没有可能是发布/订阅问题?
这里是我的代码:
list.html
<Template name="list">
<div>
<button class="btn btn-info" data-action="show" id="show">Show</button>
<button class="btn btn-danger" data-action="hide" id="hide">Hide</button>
{{ #if toggleGet }}
{{> anotherTemplate}}
{{ /if }}
</div>
</Template>
list.js
Template.list.created=function(){
this.toggle = new ReactiveVar(true);
};
Template.list.helpers(
{
toggleGet: function(){
return Template.instance().toggle.get();
}
}
);
Template.list.events(
{
//Sets toggle to true, shows anotherTemplate
'click [data-action="show"]': function(event, template) {
template.toggle.set(true);
},
//Sets toggle to false, hides anotherTemplate
'click [data-action="hide"]': function() {
template.toggle.set(false);
}
}
);
任何帮助将不胜感激,谢谢:)。
【问题讨论】:
标签: javascript meteor undefined referenceerror