您的位置:首页 > Web前端 > JavaScript

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

2010-10-13 15:24 288 查看


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

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: