[英]Meteor open / close modal
I'm trying to open or close a modal on the click of a button. 我试图通过点击按钮打开或关闭模态。
My current template looks like this: 我当前的模板如下所示:
<template name="Nav">
{{#if currentUser}}
<button class="settings_toggle">
{{email}}
</button>
{{#if settingsMode}}
<div class="settings_modal">
<a href="/create">Your Menus</a>
<a href="" class="log_out">Sign Out</a>
</div>
{{/if}}
{{else}}
<button class="log_in_toggle">
Sign In
</button>
{{#if loginMode}}
<div class="loginModal">
{{> atForm}}
</div>
{{/if}}
{{/if}}
</template>
And in a corresponding .js file I've set up the necessary helpers and events: 在相应的.js文件中,我设置了必要的帮助和事件:
Template.Nav.onRendered(function(){
Session.set('settingsMode',true);
Session.set('loginMode',true);
});
Template.Nav.helpers({
loginMode(){
return Session.get('loginMode');
},
settingsMode(){
return Session.get('settingsMode');
}
});
Template.Nav.events({
'click .settings_toggle'(event){
Session.set('!settingsMode');
},
'click .log_in_toggle'(event){
Session.set(!'loginMode');
}
});
Template.Nav.events({
'click .settings_toggle'(event){
Session.set('!settingsMode');
},
'click .log_in_toggle'(event){
Session.set(!'loginMode');
}
});
Now, I assume this is because of my limited knowledge of javascript, but how would I properly get it to work so that when .log_in_toggle
is clicked, it sets loginMode
to false if true and vice versa. 现在,我想这是因为我有限的JavaScript知识,但我将如何正确地得到它的工作,这样,当
.log_in_toggle
被点击,它设置loginMode
为false如果为true,反之亦然。
Since you have jQuery, you can easily show/hide elements on click events. 由于你有jQuery,你可以轻松地显示/隐藏点击事件的元素。 I don't see a reason to have sessions here.
我没有理由在这里举行会议。
Events: 事件:
'click .settings_toggle': function(){
//Shows a hidden element
$('.elementClass').show()
}
'click .close_modal': function(){
//Hides element
$('.elementClass').hide()
}
In your CSS, have both of the modals have display: none;
在你的CSS中,两个模态都有
display: none;
as the jQuery .show()
will make them visible. 因为jQuery
.show()
会使它们可见。
In your helpers, and .onRendered()
, just erase the sessions because you already display the right elements by checking {{#if currentUser}}
and your modals will be initially hidden with CSS and you'll show them with click event. 在您的助手和
.onRendered()
,只需擦除会话,因为您已经通过选中{{#if currentUser}}
显示了正确的元素,并且您的模态最初将使用CSS隐藏,您将使用click事件显示它们。
EDIT 编辑
Additionally, you have two Template.Nav.events({})
. 此外,您有两个
Template.Nav.events({})
。 You can't do that. 你不能这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.