2013-10-07 31 views
0

我有一个流星的问题,以及我用滑块显示一些组。当你点击一个组时,我会显示一些用户。如何比较mongoDB中的两个字段?

我想只显示用户属于管理员组,在组管理,并只对团体管理者等用户管理器...

HTML:

<template name="manage"> 
    {{> header}} 

    <div class="menu"> 
     <div class="accordion"> 
      <div class="accordion-group"> 
      {{#each roles}} 
<div class="accordion-heading country"> 
      <!-- <img src="http://placehold.it/100x30" alt="country flag" style="float:left; margin: 3px 10px 0 3px; text-align:center;"/> --> 
      <p style="border: 1px solid grey; border-radius: 5px; font-weight: bold; width: 100px; height :30px; float:left; margin: 3px 10px 0 3px; text-align:center;">{{name}}</p> 
     <a class="accordion-toggle" data-toggle="collapse" href="#country{{_id}}">{{pays}} - {{lieu}} - {{increment}}</a> 
    </div> 
    <div id="country{{_id}}" class="accordion-body collapse"> 
     <div class="accordion-inner"> 
     <table class="table table-striped table-condensed"> 
      <thead> 
      <tr> 
       <th>Utilisateurs</th> 
       <th>Nom</th> 
       <th>Prenom</th> 
       <th>Statut</th> 
       <th>ID</th> 
      </tr> 
      </thead> 
      <tbody> 
      {{#each users "1"}} 
      <!-- {{#if roles "lol"}} --> 
      <tr> 
       {{#each emails}} 
       <td>{{address}}</td> 
       {{/each}} 
       <td>{{profile.name}}</td> 
       <td>{{profile.name}}</td> 
       <td>OK</td> 
       <td>{{increment}}</td> 
      </tr> 
      <!-- {{/if}} --> 
      {{/each}} 
      </tbody> 
     </table> 
     </div> 
    </div> 
    {{/each}} 
    </div> 
</div> 

JS:

Template.manage.roles = function() { 
    return Meteor.roles.find(); 
}; 


Template.manage.users = function (inc) { 
    return Meteor.users.find({increment : inc}); 
}; 

所以,我试图比较数据库中的两个领域,但你有更好的解决方案吗? 对不起,我是新的流星:)

回答

0

一个方法来解决它,将存储选定的组在会话中,然后让你的Meteor.users.find()反应会话变量。 流星中的会话具有内在的反应性。

实施例:

<template name="manage"> 
    <button class="role" value="manager">Manager</button> 
    {{#each users}} 
    {{name}} 
    {{/each}} 
</template> 

Template.manage.events({ 
    'click .role': function(event, template) { 
    Session.set('role', event.target.value); 
    } 
}); 

Template.manage.helpers({ 
    users: function() { 
    return Meteor.users.find({role: Session.get('role')}); 
    } 
}); 
+0

尼斯!!!非常感谢 !是工作 !但是,我可以从检索一个值吗?因为