将div插入模板

时间:2014-01-16 05:58:53

标签: javascript html meteor

我已经为登录用户的3个条件写了一个帮助器。我已经验证了在client.js和浏览器控制台上使用console.log登录用户登录时正在填充CurrentUsers集合。我不确定我是否会犯这个错误或者是否有点错误。服务器控制台或浏览器控制台中没有错误消息,但没有显示0个用户登录的情况。

JS:

CurrentUsers = new Meteor.Collection("currentUsers")

if (Meteor.isClient) {
  Template.lobby.nousers = function() {
    return CurrentUsers.find().count() === 0;
    }
  Template.lobby.oneuser = function(){
    return CurrentUsers.find().count() === 1;
  }
  Template.lobby.twousers = function(){
    return CurrentUsers.find().count() === 2;
  }
}

if (Meteor.isServer) {
  Meteor._onLogin  = function (userId){
    if(CurrentUsers.find({user: userId}).count()===0){
      CurrentUsers.insert({user: userId})
    }
  }
   Meteor._onLogout  = function (userId){
    CurrentUsers.remove({user: userId})
   }
} 

HTML:

<head>
  <title>bubblepopper</title>
</head>

<body>
    {{loginButtons align = "right"}}
</body>
<template name = "lobby">
{{#if nousers}}
<div class = "nouser">
    Hello please sign in to enter the game lobby.
</div>
{{/if}}
</template>

1 个答案:

答案 0 :(得分:1)

您遗失了{{> lobby}}

<body>
    {{loginButtons align = "right"}}
    {{> lobby}}
</body>

另外,据我所知,Meteor不提供登录/注销挂钩,因此Meteor._onLoginMeteor._onLogout无法开箱即用:https://github.com/meteor/meteor/issues/1074

event-hooks包可能对您有用。

相关问题