我是node.js的初學者,在評估evalMath()函數後出現問題。尤其是,將Math2的值賦值給yScale。將值賦給node.js中的變量
Math2是一個網頁的輸入框,它引入了一個簡單的等式,如'Ir = Vr/R'。該字符串值從網頁傳遞到node.js上實現的Web服務器。在那裏,函數evalMath()被執行,它用一個相應的整數值代替Vr(用一個字符串)和R代替。在執行這個函數之後得到像這樣的'ANI0 [i] -ANI5 [i]/10',它存儲在變量Math2中。該功能完美工作。但是,當將Math2分配給yScale時,只保存'Ir = Vr/R',而不是執行evalMath() - >'ANI0 [i] -ANI5 [i]/10'後獲得的字符串。我不知道爲什麼。
if (yScale == 'Math2') {
console.log('Math2 selected');
evalMath(textAD0,textAD1,textAD2,textAD3,textAD4,Math2,Rb,Rc,R,yScale);
yScale = Math2;
console.log ("yScale: "+ yScale);
} else {
console.log("Nothing to change :) - No eqn");
}
function evalMath(labelAD0, labelAD1, labelAD2, labelAD3,
labelAD4, entry, entry1, entry2, entry3, entry4) {
iAD0="",iAD1="",iAD2="",iAD3="",iAD4="",iR="",iRb="", iRc="", iEq="";
var iAD0 = entry.search(labelAD0);
var iAD1 = entry.search(labelAD1);
var iAD2 = entry.search(labelAD2);
var iAD3 = entry.search(labelAD3);
var iAD4 = entry.search(labelAD4);
var iR = entry.search('R');
var iRb = entry.search('Rb');
var iRc = entry.search('Rc');
var iEq = entry.search('=');
if (iAD0 > "0"){ entry = entry.replace(labelAD0,'(ANI0[i]-ANI5[i])'); }
else{console.log("Nothing to change AD0")}
if (iAD1 > "0"){ entry = entry.replace(labelAD1,'(ANI1[i]-ANI5[i])'); }
else{console.log("Nothing to change AD1")}
if (iAD2 > "0"){ entry = entry.replace(labelAD2,'(ANI2[i]-ANI5[i])'); }
else{console.log("Nothing to change AD2")}
if (iAD3 > "0"){ entry = entry.replace(labelAD3,'(ANI3[i]-ANI5[i])'); }
else{console.log("Nothing to change AD3")}
if (iAD4 > "0"){ entry = entry.replace(labelAD4,'(ANI4[i]-ANI5[i])'); }
else{console.log("Nothing to change AD4")}
if (iRb > "0"){ entry = entry.replace('Rb',entry1); }
else{console.log("Nothing to change Rb")}
if (iRc > "0"){ entry = entry.replace('Rc',entry2); }
else{console.log("Nothing to change Rc")}
if (iR > "0"){ entry = entry.replace('R',entry3); }
else{console.log("Nothing to change R")}
if (iEq > "0"){ entry = entry.slice(iEq+1,entry.length); }
else{console.log("Nothing to change iEq")}
console.log("entry: " + entry);
return entry;
}