ExtJs学习之路--从Grid中得到数据

    


               

     function GetJSON(grid, colm, k) {

        var rowCount = grid.getStore().getCount();
        var JSONArray =new Array();
        var colCount = colm.getColumnCount();
        
for (var i =0; i < rowCount; i++) {
            var JSONObjStr ="{";
            
for (var j = k; j < colCount; j++) {
                var colName = grid.getColumnModel().getDataIndex(j);
                var tempObj = grid.getStore().getAt(i).get(colName);
                tempObj = (tempObj +"").replace(/(^\s*)|(\s*$)/g, "");
                tempObj = tempObj.replace(/\\/g, '\\\\');
                tempObj = tempObj.replace(/\"/g, '\\\"');                

tempObj = tempObj.replace(/\'/g, '\\\'');
                
// tempObj = tempObj.replace(/\b/g, '\\b');                

tempObj = tempObj.replace(/\r/g, '\\r');
                tempObj = tempObj.replace(/\n/g, '\\n');
                tempObj = tempObj.replace(/\t/g, '\\t');
                tempObj = tempObj.replace(/\f/g, '\\f');
                
if (j == k) {
                    JSONObjStr +=''+ colName +':'+'"'+ tempObj +'"';
                } else {
                    JSONObjStr +=','+ colName +':'+'"'+ tempObj +'"';
                }
            }
            JSONObjStr +="}";
            JSONArray.push(Ext.util.JSON.decode(JSONObjStr));
        }
        
return Ext.util.JSON.encode(JSONArray);
    }

 

 

posted @ 2010-10-13 15:24  伽马科技.攻城师  阅读(226)  评论(0编辑  收藏  举报
天空网站统计分析系统