You can’t do it that way. The database.transaction function is probably asynchronous and remote more than js runtime to answer.
Do so:
var pegaNomeMedico = {
nome : function(callback){
banco.transaction(function(tx){
tx.executeSql (sqlMedicos.selecionaTodosOsMedicosSemFiltros, [], function(tx, resposta){
var resp = resposta.rows.item(0).nome_medico;
If (typeof callback == "function")
callback(resp);
})
})
}
}
pegaNomeMedico.nome(function(resposta){
alert(resposta);
});
EDIT
At the user’s request in the comments:
var pegaNomeMedico = {
nome: null,
pegaNome: function(){
return this.nome;
},
pegaNomeServidor : function(callback){
banco.transaction(function(tx){
tx.executeSql (sqlMedicos.selecionaTodosOsMedicosSemFiltros, [], function(tx, resposta){
var resp = resposta.rows.item(0).nome_medico;
pegaNomeMedico.nome = resp;
if (typeof callback == "function")
callback(resp);
})
})
}
}
You continue using the function directly like this:
pegaNomeMedico.pegaNomeServidor(function(resposta){
alert(resposta);
});
However, there is also the possibility of:
pegaNomeMedico.pegaNome();
Note that in order to use stickName() you will need to understand that if called before return from stickNew(), you will get as a response null
. This is unavoidable, because it is the execution time of the JS query x execution time, which are not simultaneous.
It seems that this function is asynchronous. How is calling it?
pegaNomeMedico.nome()
?– Woss