zoukankan      html  css  js  c++  java
  • js foreah 循环无法跳出

    需求是:foreach循环出每个element,if判断element是否符合需求,如果不符合直接停止不执行后面的代码

      一开始直接用return 结果测试发现无效,后面的代码还是会一直执行

      break也无效

    解决 try{}catch{}捕获异常

      如果if判断位false直接抛出异常,在catch里return

    function addLogistics() {
                    try {
                        var selectRows = $("#bootstrap-table").bootstrapTable('getSelections');
                        selectRows.forEach(element => {
                           
                            if (element.orderPayStatus != 2 || element.orderDeliveryStatus != 1) {
                                $.modal.alertWarning("选中订单含有未支付或已发货订单,不能发货!");
                                throw new Error("End")
                            }
                        });
                    } catch (error) {
                        return;
                    }
                    table.set();
                    var arrays = $.table.selectColumns("orderId");
                    console.log(arrays);
                    var logisticsUrl = prefix + "/logistics" +"?orderIds="+ arrays +"&length="+ arrays.length;
                    $.modal.open("批量发货", logisticsUrl);
                }
  • 相关阅读:
    Tomcat 配置 login 和 gas
    Mac系统终端命令行不执行命令 总出现command not found解决方法
    NodeJS入门---nodejs详细安装步骤
    Android UI 自动化-Android环境安装
    UI自动化-Chrome元素定位插件CreateXpath的安装及使用
    eclipse解决中文乱码
    pytest的allure的环境配置
    pytest基础简介及实践举例
    Appium 工作原理及 Desired Capabilities
    Appium_adb常用命令总结
  • 原文地址:https://www.cnblogs.com/sspox/p/12963826.html
Copyright © 2011-2022 走看看