vRO indexOf 未返回预期结果

vRO indexOf not returning expected result

我遇到这个问题的时间比我应该遇到的时间长,所以我想我会联系这里的好人,他们知道他们在做什么。我在请求表单上有一个字段,它看起来是另一个字段的输入,然后应该 return 一个域列表,具体取决于其他选项。但是,无论输入表单、操作(和我测试脚本的工作流程)的选项如何,return 都是第一个选项 UK1、UK2。 resPolicyId 输入如下所示:

MAN-XXX-UK 或 LIS-XXX-EU - 其中 XXX 是 3 位数的团队代码...例如 MAN-WEB-UK 等等。

非常感谢任何帮助,提前致谢。

if (resPolicyId == null || resPolicyId == "" ) {
return null;
}


if (resPolicyId.indexOf("UK" != -1)) {
return arrDomains = ["UK1","UK2"]
}
else if (resPolicyId.indexOf("EU" != -1)) {
return arrDomains = ["EU1","EU2"]
}
else {return arrDomains = ["No Match Found"]}

我也尝试过其他选项,例如:

if (resPolicyId == null || resPolicyId == "" ) {
    return null;
    }

if  (resPolicyId.indexOf("UK", 8)) {
    return arrDomains = ["UK1","UK2"]
    }
    else if (resPolicyId.indexOf("EU", 8)) {
    return arrDomains = ["EU1","EU2"]
    }
    else {return arrDomains = ["No Match Found"]}

把你的条件移到外面indexOf

resPolicyId ="LIS-WEB-EU "

function input(resPolicyId){
if (resPolicyId == null || resPolicyId == "" ) {
return null;
}

if (resPolicyId.indexOf("UK") != -1) {
return arrDomains = ["UK1","UK2"]
}
else if (resPolicyId.indexOf("EU" ) != -1) {
return arrDomains = ["EU1","EU2"]
}
else {return arrDomains = ["No Match Found"]}
}
console.log(input(resPolicyId))

// clic run
var resPolicyId = null;
console.log(example(resPolicyId)); // --> null
resPolicyId = "";
console.log(example(resPolicyId)); // --> null
resPolicyId = "senseless";
console.log(example(resPolicyId)); // --> null
resPolicyId = "ABC-DEF-UK-toomuch";
console.log(example(resPolicyId)); // --> null
resPolicyId = "ABC-DEF-UK";
console.log(example(resPolicyId)); // --> ["UK1", "UK2"]
resPolicyId = "LIS-XXX-EU";
console.log(example(resPolicyId)); // --> ["EU1", "EU2"]
resPolicyId = "NYC-XXX-US";
console.log(example(resPolicyId)); // --> []


function example(resPolicyId){
  var result = null;
  if (resPolicyId && resPolicyId.length > 0 && resPolicyId.split("-").length == 3){
    resPolicyId = resPolicyId.split("-")[2];
    switch (resPolicyId){
      case "UK": result = ["UK1", "UK2"];
        break;
      case "EU": result = ["EU1", "EU2"];
        break;
      //add more sites here.... don't forget the "break"
      default: result = [];
    }
  }
  return result;
}