zoukankan      html  css  js  c++  java
  • Ext 行统计有意思的实现.(js对象的循环, ext列的设置)

    考勤界面, 列包含日期. 行的数据格式:  需要实现 编辑一列然后在最后产生的统计的效果.

    行数据内容.


    Gird Load 的时候统计数据: 
    -- 根据对象. 可以Ext.Date.parse 成功的都是日期列. 其他非日期列则不会执行统计.

    function AttenAllStaticsCalc() {
        for (var i = 0; i < AttendanceTable.store.data.items.length; i++) {
            var record = AttendanceTable.store.data.items[i];
            var recordData = record.data;
            var staticQty = {};
            for (var k in recordData) {
                var tm = Ext.Date.parse(k, 'Ymd')
                var recordDatas = recordData[k];
                if (tm) {
                    if (recordData[k]) {
                        if (staticQty[recordData[k]] != undefined) {
                            staticQty[recordData[k]] += 1;
                        } else {
                            staticQty[recordData[k]] = 1;
                        }
                    }
                }
            }
    
            var res = "";
            if (staticQty) {
                for (var t in staticQty) {
                    if (staticQty[t]) {
                        var si = t + ": " + staticQty[t] + "; ";
                        res += si;
                    }
                }
            }
            if (res.length > 0) {
                res = res.substring(0, res.length - 2);
            }
            recordData['AttenStatics'] = res;
            //record.set("AttenStatics", res); //显示数据
        }  
        
        AttendanceTable.view.refresh();    
    }

    每行编辑后设置统计数字; 

                var staticQty = {};
                for (var k in recordData) {
                    var tm = Ext.Date.parse(k, 'Ymd')
                    var recordDatas = recordData[k];
                    if (tm) {
                        if (recordData[k]) {
                            if (staticQty[recordData[k]] != undefined) {
                                staticQty[recordData[k]] += 1;
                            } else {
                                staticQty[recordData[k]] = 1;
                            }
                        }
                    }
                }
    
                //oldValue, newValue -1 + 1动作
                staticQty[oldValue] = staticQty[oldValue] - 1;
                staticQty[newValue] = typeof(staticQty[newValue]) == 'undefined' ? 1 : staticQty[newValue] + 1;           
    
                var res = "";
                if (staticQty) {
                    for (var t in staticQty) {
                        if (staticQty[t]) {
                            var si = t + ": " + staticQty[t] + "; ";
                            res += si;
                        }
                    }
                }
                if (res.length > 0) {
                    res = res.substring(0, res.length - 2);
                }
    
                record.set("AttenStatics", res); //显示数据  

    使用

  • 相关阅读:
    uva 10881
    uva 1388
    【USACO 3.2.5】魔板
    【USACO 3.2.4】饲料调配
    【USACO 3.2.3】纺车的轮子
    【USACO 3.2.2】二进制数01串
    【USACO 3.2.1】阶乘
    【USACO 3.1.6】邮票
    【USACO 3.1.5】联系
    【USACO 3.1.4】形成的区域
  • 原文地址:https://www.cnblogs.com/hijushen/p/10559321.html
Copyright © 2011-2022 走看看