2013-10-07 34 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

尼斯!!!非常感謝 !是工作 !但是,我可以從檢索一個值嗎?因爲