You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

修改JS代码:实现已选下拉框间无跳过的告警功能

修改后的JavaScript代码及逻辑说明

修正后的完整代码

if (document.getElementById('actionId').value == 'recommendWithFin') {
    var curRevSeqId = parseInt(document.getElementById('currentReviewerSequence').value);
    var allRevLen = allReviewersArray.length;
    if (allRevLen <= curRevSeqId) {
        alert('You must select the next approver before recommending the quote.');
        valid = valid && false;
    } else {
        // 收集当前审核序列之后所有已选中的审核者索引
        var selectedIndices = [];
        for (var i = curRevSeqId; i < allRevLen; i++) {
            if (allReviewersArray[i] != null && allReviewersArray[i] !== '') {
                selectedIndices.push(i);
            }
        }

        // 仅当选中至少两位审核者时,检查是否存在跳过
        if (selectedIndices.length >= 2) {
            var firstSelected = selectedIndices[0];
            var lastSelected = selectedIndices[selectedIndices.length - 1];
            // 遍历第一个到最后一个选中索引的区间,检查是否有空项
            for (var j = firstSelected; j <= lastSelected; j++) {
                if (allReviewersArray[j] == null || allReviewersArray[j] === '') {
                    alert('Please do not skip approver');
                    valid = valid && false;
                    break;
                }
            }
        }
    }
}

关键逻辑调整说明

  1. 修复索引越界问题:原代码遍历i <= allRevLen会访问数组外的undefined项,改为i < allRevLen匹配数组索引规则。
  2. 精准筛选选中项:先收集当前审核序列之后所有已选中的审核者索引,避免无差别遍历全部项导致的误触发。
  3. 区间检查跳过行为:仅当选中至少两位审核者时,检查第一个到最后一个选中项的区间内是否存在空项——只要区间内有空项,说明存在跳过;若仅选中单个项或未选中全部项但区间内无空项,不会触发告警。
  4. 类型安全处理:将curRevSeqId转为整数,避免字符串与数字比较的潜在错误。

内容的提问来源于stack exchange,提问作者divya srinivas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 01:35:20