meteor
  • meteor-blaze
  • meteor-useraccounts
  • 2017-06-21 86 views 0 likes 
    0

    我使用流星useraccounts:bootstrap。 在我的导航栏上,我有btnLogin和btnLogOut。我只希望我的登录按钮显示在IM注销,只注销按钮时,即时通讯登录流星useraccounts手表状态

    我的逻辑:

    if (!error) { 
        if (state === "signIn") { 
         document.getElementById('btnLogin').style.display = 'none'; 
        } 
        else if (state != 'signIn') { 
         document.getElementById('btnLogOut').style.display = 'visible'; 
        } 
    

    如何让我的应用程序来寻找状态,而不触发事件/点击?

    谢谢!

    回答

    1

    如果您已经登录,Meteor.userId()将返回当前用户的_id。

    所以,你可以有这样的事情:

    page.html中:

    {{#if isUserLoggedIn}} 
         <<<<<show logout button >>>>>> 
    {{else}} 
         <<<<<show login button >>>>>> 
    {{/if}} 
    

    page.js

    Template.page.helper({ 
        isUserLoggedIn: function(){ 
          if(Meteor.userId()){ 
           return true; 
          } 
          return false; 
        } 
    }); 
    
    +0

    完美!正是我想要的和流星! – user3323307

    相关问题