1
My job gerarContatosChamado
returns an HTML table formatted with the values it receives from the parameter records
, This works properly the table comes all formatted with the right data from all contacts.
The problem happens on the line href
where I call the function: gerenciarContatosChamado(\'atualizar\',resposta.contato,\'table\')
the console claims that the response variable is undefined, which is strange because I can use it within the entire for after it is returned from the immediate execution function.
The code:
function gerarContatosChamado(records)
{
var contatosTable = '';
contatosTable +=
'<tr>'+
'<td>'+
'Nome'+
'</td>'+
'<td style="text-align:center !important;">'+
'Telefones'+
'</td>'+
'<td style="text-align:center !important;">'+
'Email'+
'</td>'+
'<td style="text-align:center !important;">'+
'Horários para contato'+
'</td>'+
'<td style="text-align:center !important;">'+
'Opções do contato'+
'</td>'+
'</tr>';
var Contatos = records.get('Contatos');
for (var i=0;i < Contatos.length;i++)
{
var resposta = function(j)
{
var objeto = {};
var contatoChamadoModel = Ext.create('contatoChamado.Model', {
idContato : records.get('Contatos')[j].idContato,
nomeContato : records.get('Contatos')[j].nomeContato,
telefonesContato : records.get('Contatos')[j].telefonesContato,
emailContato: records.get('Contatos')[j].emailContato,
horariosContato: records.get('Contatos')[j].horariosContato,
tipoHorarioContato: records.get('Contatos')[j].tipoHorarioContato
});
objeto.contato = contatoChamadoModel;
return objeto;
}(i);
// protocoloChamado: records.get('protocoloChamado')
//var aux_TelefonesContato=itensContato[1].split(",");
//var aux_TiTleTelefonesContato='Telefones: \n';
// var horariosContato;
// if(contato.tipoHorarioContato == 1)
//horariosContato = '24 horas';
//else if (contato.tipoHorarioContato == 2)
//horariosContato = 'horário comercial';
//else
//horariosContato = 'personalizado: '+contato.horariosContato;
contatosTable +=
'<tr>'+
'<td>'+
resposta.contato.get('nomeContato')+
'</td>'+
'<td>'+
resposta.contato.get('telefonesContato')+
'</td>'+
'<td>'+
resposta.contato.get('emailContato')+
'</td>'+
'<td style="text-align:center !important">'+
resposta.contato.get('horariosContato')+
'</td>'+
'<td style="text-align:center !important">'+
'<a href="javascript:gerenciarContatosChamado(\'atualizar\',resposta.contato,\'table\')">Modificar</a> <img src="../extjs/shared/icons/fam/user_edit.png"> <a href="javascript:void(0)"'+
'</td>'+
'</tr>';
}
return '<div class="CSSTableGenerator" >'+
'<table >'+
'<tr>'+
'<td colspan=5>'+
'Contatos'+
'</td>'+
'</tr>'+
contatosTable
+ '</table>'+
'</div>';
}
When you call
gerenciarContatosChamado
using Javascript inline, any reference to the variable needs to be global, and thereforeresposta
is out of scope. There is no way you can pass this object without a more radical change in this code.– bfavaretto
About the formatting of the question, until it is reasonable :) Explain what you could not do that we teach you.
– bfavaretto
Thanks for the quick response. About the formatting, I don’t remember the code and I forgot to mention that there in the reply part.contact.get('variable') the answer is returned correctly, which can then be that it doesn’t work inside the href?
– José
You’re welcome. I just didn’t post the same answer (in the field below) because I don’t have time to elaborate a complete solution.
– bfavaretto
That code in href only runs when you click on the link. And then it will look for a variable
resposta
global, which does not exist, when in fact you wanted a specific response object that you generate during the loop and is out of scope. Then I’ll see if I can give you a way if no one else does. About formatting, the site does not deal well with tabs, if you always use spaces to indent is ok.– bfavaretto
Try to avoid javascript inline in html, think the solution would be more around.
– bfavaretto