2017-10-18 9 views
0

node、express、swigを使用しています。私はローカル変数であるcurrentUserに基づいてループを実行できるようにしたいと考えています。私はループを稼働させましたが、それはすべてのユーザーのために私たちの結果を吐き出しています。ここでループベースuser.id

は私のループです:

{% for ap in aps %} 
    <tr> 
    <td>{{ap.name}}</td> 
    <td>{{ap.manufacturer}}</td> 
    <td>{{ap.model}}</td> 
    <td>{{ap.type}}</td> 
    <td>{{ap.notes}}</td> 
    </tr> 
{% endfor %} 

マイ部分ルート(他のループのために取り外した部品):

// show model 
    app.get('/dashboard/it/model', 
    setRender('dashboard/it/model'), 
    setRedirect({auth: '/login'}), 
    isAuthenticated, 
    (req, res, next) => { 
     AP.find({}, function(err, allAP) { 
      if(err){ 
       console.log(err); 
      } else { 
       res.locals.aps = allAP; // Set the data in locals 
      } 
     }); 

     Custom.find({}, function(err, allCustom) { 
      if(err){ 
       console.log(err); 

      } else { 
       res.locals.customs = allCustom; // Set the data in locals 
       next(); 
      } 
     }); 

    }, 
    dashboard.getDefault 
); 

答えて

0

はIDが間違っていると動作しません、あなたが変更する必要がオフに基づいてループします検索パラメータをIDで除外して、"author.id":req.user.idをmongoドキュメントのどこにクエリーパラメータを置くかを指定する必要があります。

関連する問題