日期:2014-05-16  浏览次数:20413 次

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);
??? }

?