Err to call the information in the database and view it in a table using tags.
Error: Can not read property 'pla_id' of undefined
Note: I am a newcomer to the development, I researched this error and saw that it is not so complicated, but I tried to insert in the pages where I was likely to find err, but I did not succeed. Below are the codes for analysis.
//ROUTES
module.exports = function (app) {
app.get('/apps/indicadores/historico-plano-de-acao', app.middlewares.isLoggedIn.isLoggedIn, function (req, res, result) {
res.render('pages/historico-plano-de-acao', {
user : req.user,
plan : result
});
});
};
// Historico do plano de acao
app.get('/apps/indicadores/historico/indicador/plano-de-acao', function (req, res) {
let data = req.query;
/*let indicadorID = data.id,
month = data.month,
year = data.year;*/
var connection = app.infra.connectionFactoryMySQL();
var mysqlDAO = new app.infra.MySQLDAO(connection, table.plano_de_acao, "plano_de_acao");
/**
* Retorna o plano correspondente ao seu indicador e de acordo com o mês e o ano.
*/
mysqlDAO.getPlanFromIndicador(data, function (err, result) {
if (err) {
console.error(err);
res.redirect("/apps/indicadores/erros/500");
} else {
console.log(result);
res.render('pages/historico-plano-de-acao', {
user : req.user,
plan : result
});
}
});
connection.end();
});
<!DOCTYPE html>
<html lang="en">
<% include ../partials/head %>
<body class="hold-transition skin-blue sidebar-mini">
<% include ../partials/header-areas-setores %>
<div class="wrapper">
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
</section>
<!-- Main content -->
<!--Historico Indicadores-->
<section class="content">
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<p hidden id='historico-plano-de-acao-id'><%=plan[0].pla_id%></p>
<!-- /.panel-heading -->
<div class="panel-body">
<div class="popup-position" id="contact-popup">
<h1> Histórico Plano de Ação</h1>
<p hidden id='historico-plano-de-acao-id'> </p>
</div>
<table width="100%" class="table table-striped table-bordered table-hover" id="myTable">
<thead>
<tr>
<th>Data</th>
<th>Resonsável Por Abrir o Plano</th>
<th>Justificativa Indicador Fora da Meta</th>
<th>Ações Tomada no Plano</th>
<th>Resonsável pelas Ações</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<% plan.forEach(function(item){ %>
<% if(item.acp_responsavel != null && item.acp_descricao != null) { %>
<tr align='center'>
<td>
<%=plan[0].pla_data%>
</td>
<td>
<%=plan[0].pla_responsavel%>
</td>
<td>
<%=plan[0].pla_justificativa%>
</td>
<td>
<%=item.acp_descricao%>
</td>
<td>
<%=item.acp_responsavel%>
</td>
<td>
</td>
</tr>
<% } %>
<%})%>
</tbody>
</table>
<!-- /.table-responsive -->
</div>
<!-- /.panel-body -->
</div>
<!-- /.panel -->
</div>
<!-- /.col-lg-12 -->
</div>
</section>
</div>
</div>
<% include ../partials/scripts %>
<% include ../partials/scripts-datapicker-datatable %>
<script>
$(document).ready(function () {
$('#myTable').DataTable({
responsive: true
});
var planoId = $('#historico-plano-de-acao-id').text();
});
</script>
</body