问题返回变量 [英] Problem returning variables
问题描述
我正在浪费很多时间去尝试做我不知道是否可能的事情:
I''m losing many time trying to do a thing I dont know if Its possible:
function botaoCarregarNotas() {
PageMethods.verNum(verNum2);
PageMethods.carregarNotas(verTexto);
}
// aqui é recebido o resultado
function verNum2(result) {
var num = result;
alert("num: "+num);
return num;
}
// recebe texto
function verTexto(resultado){
var num = verNum2(paremeter); // HERE IS THE PROBLEM
alert("num1: "+num);
for(i=0; i< num; i++)
loadNotes(resultado[i]);
因为我正在使用AJAX,所以我需要使用这三个函数,并且我需要返回在verNum2()处分配的num变量,并在verTexto()处使用它.在我使用时,它显然是错误的. -我得到"num1:未定义",因为我需要传递要返回的参数.
我该如何解决这个问题?
Because I''m using AJAX I need to use this three functions, and I need to return num variable assigned at verNum2(), and use it at verTexto(). As I am using, its obviously wrong. - I get "num1: undefined", because I need to pass the parameter that I want to return.
How can I solve this problem ?
推荐答案
您正在调用verNum2,而没有任何参数,例如:
You are calling verNum2 without any parameters, like this:
var num = verNum2();
而且由于您不带参数调用它,因此没有任何内容可分配给num:
And because you called it without a parameter it has nothing to assign to num:
function verNum2(result) {
var num = result;
alert("num: "+num);
return num;
}
Num
是您返回的内容,由于未调用result
,因此未分配.
祝你好运!
Num
is what you return and that is then unassigned because result
was when calling it.
Good luck!
当然这是行不通的.看它.
verNum2使用一个参数,该参数将其分配给局部变量,然后将其返回.在verTextTo中调用它时,您没有提供参数,这意味着将返回NULL.
Of course this doesn''t work. Look at it.
verNum2 takes one parameter which assigns it to a local variable and then returns it. When you are calling it in verTextTo you are not giving a parameter, which means NULL will be returned.
尝试一下,
try this,
function botaoCarregarNotas_VerNum()
{
PageMethods.verNum(verNum2);
}
function botaoCarregarNotas()
{
PageMethods.carregarNotas(verTexto);
}
// aqui é recebido o resultado
function verNum2(result)
{
var num = result;
alert("num: "+num);
return num;
}
// recebe texto
function verTexto(resultado)
{
var num = botaoCarregarNotas_VerNum();
alert("num1: "+num);
for(i=0; i<num;>
loadNotes(resultado[i]);
}
这篇关于问题返回变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!