在Jade模板上返回值

时间:2016-05-04 20:05:54

标签: node.js pug

我在db上有三个寄存器,当我each project in projects我可以看到内容重复至少三次但是当我#{project.ProjectName}分页时,这是我的代码:

extends ../includes/layout

block content
  div(class="wrap")
    include ../includes/header
    div(class="ink-grid")
      div(class="column-group vertical-space")
        div(class="all-50")
          a(href="project/create")
            button(class="ink-button green") Crear proyecto
      div(class="column-group vertical-space")
        div(class="all-20")
          each project in projects 
            figure(class="ink-image")
              figcaption(class="over-top dark")  testing //#{project.ProjectName} 
              img(src="images/splash.768x1004.png")

      div(class="push")          
  include ../includes/footer

控制器......

plain : function (req, res, doc) {
      //Datos cocinados con la respuesta...
      if(!req.user){
        res.redirect('/user/login');
      }
      res.render('project/resume', {
        // resume page view parameters
        title : "proyectos",
        user : req.user,
        projects : Project,

      });
      Project.find({});
    },

1 个答案:

答案 0 :(得分:0)

<强>解决

这就是我所做的,同时,我添加了一个&#34;过滤器&#34;谁只是显示用户的项目。来了:

plain : function (req, res) {
      //Datos cocinados con la respuesta...
      if(!req.user){
        res.redirect('/user/login');
      }
      Project.find({ ProjectOwner : req.user._id}, function(err, projects){
        console.log("***content from Project***")
        console.log(projects)
        res.render('project/resume', {
          // resume page view parameters
          title : "proyectos",
          user : req.user,
          projects : projects,
        });
      });
    },