我应该使用currenttest值在testorder数组中找到当前位置。我需要从该索引开始并继续前进,以寻找trueVitals可用性。任何帮助将非常感激。当前代码的缺点是,很难全面测试功能“ if(mode ==“ bpw”&currenttest ==“ ECG”)“中的每个代码路径
var json_data = {
"Blood Pressure": true,
"Weight Scale": true,
"Body Composition": true,
"ECG": true,
"SPO2": false,
"temp": true
};
var hardwarelist = [];
var testorder = ["Blood Pressure", "Weight Scale", "Body Composition", "ECG", "SPo2", "temp"];
for (var i in json_data) {
hardwarelist.push([i, json_data[i]]);
}
var trueVitals = hardwarelist.filter(([, e]) => e).map(([e]) => e);
var mode = "bpw";
var currenttest = "ECG";
nextTest(mode, currenttest);
function nextTest(mode, currenttest) {
var currenttestorder = (testorder.indexOf(currenttest));
if (mode == "bpw" & currenttest == "ECG") {
if(trueVitals.includes("Weight Scale"){
window.location.href = "#/about";
}
else if (trueVitals.includes("ECG")) {
window.location.href = "#/services";
} else if (trueVitals.includes("SPO2")) {
window.location.href = "#/contact";
} else if (trueVitals.includes("Body Composition")) {
window.location.href = "#/blog";
} else if (trueVitals.includes("temp")) {
window.location.href = "#/faq";
}
}
}