javascript之求最值

本文介绍了一种通过JavaScript从表格中获取数据并计算成本价格与电子商品价格最小值的方法。利用jQuery DataGrid插件获取所有行数据,然后计算每个项目的成本价格与售价之差,并找出这些差值及售价中的最小值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

求最值:

    var selections = $("#deliveryGridSalesOrGoods").datagrid('getRows');
        var costPrice = '';
        var ecPrice='';
        if (selections != null && selections != '') {
            for (var i = 0; i < selections.length; i++) {
                costPrice += selections[i].ecPrice-selections[i].costPrice+',';
            }
        }
        if(costPrice!=null){
            costPrice = costPrice.substring(0, costPrice.lastIndexOf(","));
        }
        if (selections != null && selections != '') {
            for (var i = 0; i < selections.length; i++) {
                ecPrice += selections[i].ecPrice+',';
            }
        }
        if(ecPrice!=null){
            ecPrice = ecPrice.substring(0, ecPrice.lastIndexOf(","));
        }
        
        
        
      var arry = new Array();
      var newEc=costPrice.split(',');
      var newecPrice=ecPrice.split(',');
//      Number(value).toFixed(2);
      var ecmin=Math.min.apply(null, newEc).toFixed(2);;//最小值
      var ec_price=Math.min.apply(null, newecPrice).toFixed(2);;//最小值

 

转载于:https://www.cnblogs.com/wangchuanfu/p/5777006.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值