-3

I am trying to put add a validation condition to a combobox. I have been able to get it to work on other combo boxes, but here I am trying to essentially add 2 validaitons on one combobox. I am not familiar with how the whole validation process works and the order of operation. My code has become convoluted and need help sorting it out.

This is the code on the validation that I am working with:

functionvalidateSLBox(v){
    if(storeSpringLync.findExact('disp',
    v)>-1)returntrue;elsereturn'Notvalid';else{
        if(v=='DC'){
            cbSLBox.enable();
        }else{
            cbSLBox.disable();
        }
    }
}
4

1 回答 1

0

当您return从一个函数中退出时,您将在该点退出。函数执行后没有其他内容,因此您永远不会到达函数的后半部分。

此外,一个else匹配一个if。你有两个elses 在这里if

你可能想要这样的东西:

functionvalidateSLBox(v){
  if(v=='DC'){
    cbSLBox.enable();
  }else{
    cbSLBox.disable();
  }

  if(storeSpringLync.findExact('disp',v) > -1){
    return true;
  }else{
    return 'Not valid';
  }
}

这将允许您启用 cbSLBox(无论是什么),同时还返回 true 或 Not valid... 如果这不是您想要的,您可以使用switch语句或只嵌套 if 语句。这实际上取决于您想要做什么,这很难从您的代码示例和描述中分辨出来。

于 2013-11-14T20:41:28.593 回答