我有一个从函数中获取值的变量。该函数包含2个PageMethods。在函数内部,一切都很完美,但变量dsrt
保持"Undefined"
。有人可以告诉我为什么函数不返回任何值?
dsrt = calculate_all_rates(ratetypes.Day1_Rate, ddlccy.options[ddlccy.selectedIndex].value, ses, ccytype.ID, ((ddltype.options[ddltype.selectedIndex].text == "Export") ? postyp.Export : postyp.Import), dt, mat2, mat2, ddlpf.options[ddlpf.selectedIndex].value, 0, 0, 0, "", ddlbank.options[ddlbank.selectedIndex].value);
function calculate_all_rates(rateid, ccy1,ccy2,ctyp,typ,posdt,matdt1,matdt2,pfid,mar,mar1,mar2 ,caltyp,bnk ) {
var rds = new Array();
var para = new Array();
para[0] = rateid;
para[1] = ccy1;
para[2] = ccy2;
para[3] = ((ctyp == 1) ? "ID" : "NAME");
para[4] = ((typ == 1) ? "Export" : "Import");
para[5] = posdt;
para[6] = matdt1;
para[7] = matdt2;
para[8] = pfid;
para[9] = mar;
para[10] = mar1;
para[11] = mar2;
para[12] = caltyp;
para[13] = bnk;
if(rateid == 9) {
PageMethods.rates(para,"avgspot",suc1,err1);
function suc1(res){rds=res;return rds;}
function err1(){}
} else {
PageMethods.rates(para,"calcrates",suc2,err2);
function suc2(res){rds=res;return rds;}
function err2(){}
}
}
dsrt
将值返回为"Undefined"
。
答案 0 :(得分:0)
尝试在函数前面放回,即
return function suc1(res){rds=res;return rds;}
答案 1 :(得分:0)
你的主要功能有任何回报
尝试
var rds;
function suc1(res){rds=res;}
return rds;
答案 2 :(得分:0)
进行以下更改。它有效。
您不能将另一个函数中的页面方法返回的值赋给dsrt。所以在调用函数
中使用dsrt和Calculate_all_rates的所有功能旧代码:
dsrt = calculate_all_rates(ratetypes.Day1_Rate, ddlccy.options[ddlccy.selectedIndex].value, ses, ccytype.ID, ((ddltype.options[ddltype.selectedIndex].text == "Export") ? postyp.Export : postyp.Import), dt, mat2, mat2, ddlpf.options[ddlpf.selectedIndex].value, 0, 0, 0, "", ddlbank.options[ddlbank.selectedIndex].value);
新代码:
function Common()
{
var rateid;var ccy1;var ccy2;var ctyp;var typ;var posdt;var matdt1;var matdt2;var pfid;var mar;
var mar1;var mar2;var caltyp;var bnk;
{rateid=ratetypes.Day1_Rate;ccy1=ddlccy.options[ddlccy.selectedIndex].value;ccy2=ses;ctyp=ccytype.ID;typ=((ddltype.options[ddltype.selectedIndex].text == "Export") ? postyp.Export : postyp.Import);posdt=dt;matdt1=mat2;matdt2=mat2;pfid=ddlpf.options[ddlpf.selectedIndex].value;mar=0;mar1=0;mar2=0;caltyp="";caltyp=bnk=ddlbank.options[ddlbank.selectedIndex].value;}
var str;
var para_arr = new Array();
para_arr[0] = rateid;
para_arr[1] = ccy1;
para_arr[2] = ccy2;
para_arr[3] = ((ctyp == 1) ? "ID" : "NAME");
para_arr[4] = ((typ == 1) ? "Export" : "Import");
para_arr[5] = posdt;
para_arr[6] = matdt1;
para_arr[7] = matdt2;
para_arr[8] = pfid;
para_arr[9] = mar;
para_arr[10] = mar1;
para_arr[11] = mar2;
para_arr[12] = caltyp;
para_arr[13] = bnk;
if(rateid == 9)
{
str="avgspot";
}
else
{
str="calcrates";
}
PageMethods.rates(para_arr,str,calc_suc,calc_err);
function calc_suc(resp)
{
dsrt=resp;
}
function calc_err(){}
}