function RowSet(json) { var BUFFER_PRIMARY = "primary"; var BUFFER_DELETE = "delete"; this._name = ""; this._className = null; this._type = ""; this._recordCount = 0; this._countSql = ""; // 统计记录数的sql语句 this._currentPage = 0; this._countSqlParamValues = ""; this._rowCount = 0; this._data = json || {}; this._metaData = {};//表单元数据 this._queryRowSetName = null;//查询表单对应的rowSet名字 this._init = function() { if(json == null) return; if(json["name"] != null) { this._name = json["name"]; } if(json["classname"] != null) { this._className = json["classname"]; } if(json["type"] != null) { this._type = json["type"]; } if(json["recordCount"] != null) { this._recordCount = json["total"]; } if(json["total"] != null) { this._rowCount = json["recordCount"]; } if(json["currentPage"]!=null) { this._currentPage = json["pageNum"]; } if(json["countSql"]!=null) { this._countSql = json["countSql"]; } if(json["countSqlParamValues"]!=null) { this._countSqlParamValues = json["countSqlParamValues"]; } if(json["metadata"] != null) { this._metaData = json["metadata"]; } if(this._data["delete"] == null) { this._data["delete"] = []; } if(this._data["rows"] == null) { this._data["rows"] = []; } if(this._data["queryRowSetName"] == null) { this._queryRowSetName = this._data["queryRowSetName"]; } } this.getMetaData = function() { return this._metaData; } this.setQueryRowSetName = function(name) { this._queryRowSetName = name this._data["queryRowSetName"] = name; } this.getName = function() { return this._name; } this.setName = function(name) { this._name = name } this._getBuffer = function(buffer) { if (BUFFER_PRIMARY == buffer || buffer == null) { return this._data["rows"]; } else { return this._data["delete"]; } } this.getRowCount = function(buffer) { return this._getBuffer(buffer).length; } this.addRow = function(data) { var data = data || {}; var row = new Row(data); this._getBuffer(null).push(data); return row; } this.addRows = function(datas) { for(var i=0,count = datas.length;i < count;i++) { this._getBuffer(null).push(datas[i]); } } this.deleteRow = function(index) { this._getBuffer(null).splice(index,1); } this.resetUpdate = function() { this._deleteBuffer = []; } this.getRow = function(index) { return new Row(this._getBuffer(null)[index]); } this.getItemValue = function(index,columnName) { return new Row(this._getBuffer(null)[index]).getItemValue(columnName); } this.setItemValue = function(index,columnName,value) { new Row(this._getBuffer(null)[index]).setItemValue(columnName,value); } this.getPrimaryData = function() { return this._data["rows"]; } this.setDeleteData = function(data) { this._data["delete"] = data; } this.setStatues = function(listData,statuesData) { for(var i=0,count = listData.length; i < count;i++) { if(listData[i]["_sys_status"] == null) { listData[i]["_sys_status"] = {}; } listData[i]["_sys_status"]["status"] = statuesData } } this.getData = function() { this._data["recordCount"] = this._recordCount; this._data["total"] = this._rowCount; this._data["countSql"] = this._countSql; this._data["currentPage"] = this._currentPage; this._data["countSqlParamValues"] = this._countSqlParamValues; //////////////////////////////////////////////////////// return this._data; } this.getRecordCount = function() { return this._recordCount; } this.setPageSize = function(pageSize) { this._data["pageSize"] = pageSize; } this.getPageSize = function() { return this._data["pageSize"]; } this.setPageNum = function(pageNum) { this._data["pageNum"] = pageNum; } this.getPageNum = function() { this._data["pageNum"]; } this.setSort = function(sort) { this._data["sort"] = sort; } /** * 复制一个干净的对象 */ this.copy = function() { var obj = {}; obj["name"] = this._name; if(this._className != null) { obj["classname"] = this._className; } obj["type"] = this._type; obj["rows"] = []; obj["delete"] = []; obj["pageSize"] = this._data["pageSize"]; obj["pageNum"] = this._data["pageNum"]; obj["countSql"] = this._data["countSql"]; obj["countSqlParamValues"] = this._data["countSqlParamValues"]; obj["queryRowSetName"] = this._queryRowSetName; return new RowSet(obj); } this._init(); }