meteor
  • meteor-blaze
  • meteor-useraccounts
  • 2017-06-21 85 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

    相關問題