车把过滤对象

Handlebars filtering object

我正在使用 Express、NodeJS 和 MongoDB。尝试使用车把传递一些信息进行渲染。

我使用的路线代码是:

router.get('/mediciones', async (req, res) => {
  // res.render('mediciones');
  const dashboard  = await Mediciones.find().limit(3);
  console.log(dashboard);
  res.render('mediciones' , { dashboard });
});

hbs 代码是:

{{#each  dashboard }}
<p>
    {{!-- {{this}} --}}      // using just one, but both show me the 3 objects
    {{.}}
</p>
{{/each}}

渲染视图:

{ _id: 5ea9ff48b54a2b09d38ddfd9, temperatura: 20, humedad: 44, heat: 19.2, temperaturaagua1: 22.31, temperaturaagua2: 22.31, ventilador: true, extractor: true, intractor: true, bombaagua: true, refreshInterval: 10000, currentMillis: 3799956, dia: 2020-04-29T22:27:20.997Z, __v: 0 }

{ _id: 5ea9ff52b54a2b09d38ddfda, temperatura: 20, humedad: 44, heat: 19.2, temperaturaagua1: 22.31, temperaturaagua2: 22.31, ventilador: true, extractor: true, intractor: true, bombaagua: true, refreshInterval: 10000, currentMillis: 3809961, dia: 2020-04-29T22:27:30.986Z, __v: 0 }

{ _id: 5ea9ff5db54a2b09d38ddfdb, temperatura: 20, humedad: 44, heat: 19.2, temperaturaagua1: 22.31, temperaturaagua2: 22.31, ventilador: true, extractor: true, intractor: true, bombaagua: true, refreshInterval: 10000, currentMillis: 3820030, dia: 2020-04-29T22:27:41.068Z, __v: 0 }

问题是:我怎样才能从这些对象中提取 "temperatura" 和 "humedad" 并将它们打印在 <p> 标签上?我尝试使用 {{temperatura}} 但没有显示。我找不到答案

try this.

const dashboard  = await Mediciones.find().limit(3).lean();

如果你这样做了会怎样

{{#each  dashboard }}
<p>
    {{temperatura}} //       // using just one, but both show me the 3 objects
    {{humedad}}
</p>
{{/each}}

?