node.js - 数据未显示在车把上
问题描述
我有下面的脚本,它从 MongoDB 中提取数据:
router.get("/visualizarinscritos/:id", eEmpresa, (req,res)=>{
result = []
Vaga.findOne({_id: req.params.id}).then((vaga)=>{
//console.log(Object.values(JSON.parse(JSON.stringify(vaga.candidatos))))
Curriculo.find().then((curriculo)=>{
if(curriculo){
for(var r = 0; r < vaga.candidatos.length ; r++){
for(var i = 0; i < curriculo.length; i++){
if(vaga.candidatos[r] == curriculo[i].usuario){
result.push(curriculo[r])
}
}
}
res.render("empresa/viewcurriculos", {curriculo: result})
}else{
req.flash("error_msg", "Não há curriculos relacionados")
res.redirect("/empresa/vagas")
}
}).catch((err)=>{
req.flash("error_msg", "Houve um erro ao buscar usuários relacionados a vaga: "+err)
res.redirect("/empresa/vagas")
})
}).catch((err)=>{
req.flash("error_msg", "Houve um erro ao carregar vaga: "+err)
res.redirect("/empresa/vagas")
})})
我正在按预期接收数据。我做了一个console.log,我得到了正确的:
[ {
_id: 60cabfad6494450bd0065877,
usuario: 60cabebfd90f8427c4840990,
experiencia: 'SAP Concur Reporting Analyst\r\n' +
'SAP SE | 07/22/2019 - Current.\r\n' +
'Support and develop reports on IBM Cognos\r\n' +
'\r\n' +
'Support team questions and handle issues\r\n' +
'\r\n' +
'Teach new colleagues\r\n' +
'\r\n' +
'Translate documents to Portuguese, English or Spanish.\r\n' +
'\r\n' +
'Create and support system automations\r\n' +
'\r\n' +
'Trilingual Service Desk Senior\r\n' +
'HCL Technologies | 02/27/2019 – 07/19/2019\r\n' +
'Teach news Service Desk Analyst\r\n' +
'\r\n' +
'Teach and remainder the team about process and new process or applications\r\n' +
'\r\n' +
'Answer the questions that the Analyst of Service Desk can ask\r\n' +
'\r\n' +
'Learn and participate of migrations of new applications\r\n' +
'\r\n' +
'Work on tickets that have a big priority\r\n' +
'\r\n' +
'Help key users solving problems and answering questions\r\n' +
'\r\n' +
'Verify the tickets that Service Desk done something and escalate it if necessary\r\n' +
'\r\n' +
'Bilingual Service Desk\r\n' +
'HCL Technologies | 05/22/2017 – 02/27/2019\r\n' +
'Support on applications that are homologated and used by the client\r\n' +
'\r\n' +
'Remote support on softwares\r\n' +
'\r\n' +
'Support on applications that are homologated and used by the client, O.S, networks and telecom\r\n' +
'\r\n' +
'improve the Knowledge base\r\n' +
'\r\n' +
'Answer emails, calls and chats according the demands\r\n' +
'\r\n' +
'Manage tickets\r\n' +
'\r\n' +
'Internship – Maintenance of computers and networks\r\n' +
'QI Escolas & Faculdades | 09/14/2016 - 05/18/2017\r\n' +
'Administrative routines\r\n' +
'\r\n' +
'Servers maintenance\r\n' +
'\r\n' +
'Maintenance of cabling and switch\r\n' +
'\r\n' +
'Remote support on applications\r\n' +
'\r\n' +
'Local support on hardware and Telecom area.',
educacao: 'Associate in Analysis and Systems Development\r\n' +
'Unisinos | 2017/2 - Current.\r\n' +
'\r\n' +
'IT\r\n' +
'QI Escolas & Faculdades | Completed at 2017',
certificacao: '>\r\n' +
'ITIL\r\n' +
'\r\n' +
'>\r\n' +
'Active Directory\r\n' +
'\r\n' +
'>\r\n' +
'Exchange\r\n' +
'\r\n' +
'>\r\n' +
'Windows Server and OS\r\n' +
'\r\n' +
'>\r\n' +
'Network maintenance/management\r\n' +
'\r\n' +
'>\r\n' +
'Hardware',
idioma: 'Porguese\r\n\r\nEnglish\r\n\r\nSpanish\r\n\r\nLIBRAS',
habilidades: 'Java\r\n' +
'\r\n' +
'SQL\r\n' +
'\r\n' +
'HTML/CSS\r\n' +
'\r\n' +
'JavaScript\r\n' +
'\r\n' +
'EJS\r\n' +
'\r\n' +
'NodeJS\r\n' +
'\r\n' +
'Android\r\n' +
'\r\n' +
'Angular\r\n' +
'\r\n' +
'PHP\r\n' +
'\r\n' +
'Cognos',
outros: 'Github: https://github.com/gabdonada\r\n\r\nFuncionou?',
__v: 0},undefined]
但是,当尝试使用下面的 Handlebars 代码获取数据时,页面未显示值:
{{#each curriculo}}
<div class="card">
<div class="card-body">
<h4>{{curriculo.usuario.nome}}</h4>
<h4>{{experiencia}}</h4>
<small>Sobre: {{curriculo.experiencia}}</small><br>
<a href="/empresa/curriculo/:{{curriculo._id}}"><button class="btn btn-success">Visualizar Curriculo</button></a>
</div>
</div>
{{else}}
<h4>Não há curriculos registrados</h4>
{{/each}}
我尝试使用和不使用每个,但仍然无法正常工作。你知道如何解决这个问题吗?
解决方案
在一个#each
块内,您需要使用this
来访问当前数组项。因此,您应该将代码更改为:
{{#each curriculo}}
<div class="card">
<div class="card-body">
<h4>{{this.usuario.nome}}</h4>
<small>Sobre: {{this.experiencia}}</small><br>
<a href="/empresa/curriculo/:{{this._id}}"><button class="btn btn-success">Visualizar Curriculo</button></a>
</div>
</div>
{{else}}
<h4>Não há curriculos registrados</h4>
{{/each}}
推荐阅读
- azure-devops - Azure Devops Pipeline:定义变量并将其用作另一步骤的任务输入
- php - WooCommerce 中基于地理位置的多个国家/地区的自定义重定向
- java - 如何从 Jdeveloper w ADF 转换/迁移到替代/优雅的 IDE (Eclipse)
- c# - 如何检测从文件夹中删除的文件
- android - AutoCompleteTextView onSubmit 事件
- python-3.x - 将处理连接并添加代理的 Python 模块?
- axapta - Dynamics AX 2012:如何通过代码获取特定表单中所有方法的列表?
- css - 如何访问/覆盖“vs-dark”或“vs”uiTheme颜色
- ansible - 定义 Ansible 配置的有效方法是什么
- kubernetes - 如何获取未链接到任何服务的 pod 列表