📄 resultset.js
字号:
// @visibility external//<allRowsCached : function () { return ( // - in fetchMode:"local" (load all data up front), data has been successfully // loaded (this.allRows != null && (!this.allRowsCriteria || this._emptyAllRowsCriteria)) || // - in other modes, we've detected emptyCriteria and full cache (this.allMatchingRowsCached() && this._emptyCriteria) );},isEmpty : function () { if (this.isPaged()) { // If there's a full cache for the current filter criteria, check the length of the data if (this.allRowsCriteria) { return this.getLength() == 0; // For a paged dataSet, the cachedRows attribute indicates we have successfully // fetched rows from the server (so this is non empty) } else if (this.cachedRows > 0) return false; } return !this.lengthIsKnown() || this.getLength() <= 0;},canSortOnClient : function () { return this.shouldUseClientSorting() && (this.allMatchingRowsCached()||isc.isOffline()) },canFilterOnClient : function () { return this.shouldUseClientFiltering() && this.allRowsCached() },//> @method resultSet.getValueMap()// Get a map of the form <code>{ item[idField] -> item[displayField] }</code>, for all // items in the list. If more than one item has the same <code>idProperty</code>, // the value for the later item in the list will clobber the value for the earlier item.// <P>// If this method is called when the +link{allMatchingRowsCached(),cache is incomplete}, it// will trigger fetches, and will return a valueMap reflecting only the currently loaded rows.//// @param idField (string) Property to use as ID (data value) in the valueMap// @param displayField (string) Property to use a display value in the valueMap// @return (object) valueMap object// @see resultSet.allMatchingRowsCached()// @visibility external//<// picked up as part of the list interface// List API// --------------------------------------------------------------------------------------------//> @method resultSet.getLength()// Return the total number of records that match the current filter criteria.// <P>// This length can only be known, even approximately, when the first results are retrieved from// the server. Before then, the ResultSet returns a large length in order to encourage viewers// to ask for rows. +link{lengthIsKnown(),ResultSet.lengthIsKnown()} can be called to// determine whether an actual length is known.//// @include List.getLength()// @visibility external//<getLength : function () { var unknownLength = this.unknownLength || isc.ResultSet.UNKNOWN_LENGTH; if (!this.lengthIsKnown()) return unknownLength; // NOTE: when paged, if we obtain a full cache with empty criteria, we set allRows to the // full cache and go into local filtering mode (if enabled). From then on, totalRows, // normally set based on server responses, is no longer up to date. return (this.isPaged() && !this.allRows ? this.totalRows : this.localData.length);},//> @method resultSet.indexOf()// Return the position in the list of the first instance of the specified object.// <p>// If pos is specified, starts looking after that position.// <p>// Returns -1 if not found.// <p>// <b>NOTE:</b> ResultSet.indexOf() only inspects the current cache of records, so it is only// appropriate for temporary presentation purposes. For example, it would not be appropriate// to hold onto a record and attempt to use indexOf() to determine if it had been deleted.//// @include List.indexOf()//<indexOf : function (item, pos, endPos) { if (this.localData == null) return -1; // ignore LOADING rows if (Array.isLoading(item)) return -1; var index = this.localData.indexOf(item, pos, endPos); if (index != -1) return index; // if not found, try lookup by primary key. The caller has an object presumably previously // retrieved from this ResultSet, but because we drop cached rows in various circumstances, // the row may either have fallen out of cache (eg different sort order) or been replaced // by a new row with different object identity. // NOTE: primarily this is called by Selection and selection-related code, because of it's // strategy of putting marker properties onto records. return this.getDataSource().findByKeys(item, this.localData, pos, endPos);},// XXX ignore slideList, which is called on D&D reorder in ListGrids. // To support this properly we should either:// - support unsort(): correctly manage the fact that our order temporarily doesn't reflect// current sort// - support permanent stored orders: if our DS declares that some field represents a permanent// stored order, and we are currently sorted by that field, assume the user means to// permanently reorder the record, and save changed field numbersslideList : function (selection, startIndex) { return; },//> @method resultSet.get()// Returns the record at the specified position.// <P>// All List access methods of the ResultSet have the semantics described in <code>getRange()</code>.// @include list.get()// @see getRange()//<get : function (pos) { if (pos < 0) { //>DEBUG this.logWarn("get: invalid index " + pos); //<DEBUG return null; } // optimization: what getRange(pos, pos+1) would do, only we can do it faster: if the // requested row is non-null, it's either cached or loading, so return it if (this.localData != null && this.localData[pos] != null) return this.localData[pos]; // if this request falls within the rows we are already planning to fetch, likewise return // the loading marker (we don't actually put the loading marker into this.localData until // the fetch request is sent to the server). if (this.fetchStartRow != null && pos >= this.fetchStartRow && pos <= this.fetchEndRow) { return Array.LOADING; } return this.getRange(pos, pos+1)[0];},//> @method resultSet.getRange()// Return the items between position start and end, non-inclusive at the end, possibly // containing markers for records that haven't loaded yet.// <P>// Calling getRange for records that have not yet loaded will trigger an asynchronous fetch. The// returned data will contain the marker value <code>Array.LOADING</code> as a placeholder for// records being fetched. If any rows needed to be fetched, <code>dataArrived()</code> will// fire when they arrive.//// @include list.getRange()// @see classAttr:Array.LOADING// @see dataArrived()// @visibility external//<getRange : function (start, end, ignoreCache, fetchNow) { if (isc._traceMarkers) arguments.__this = this; // If end is null, assume its start+1 - just fetch the start row. if (start == null) { this.logWarn("getRange() called with no specified range - ignoring."); return; } if (end == null) end = start+1; if (this.isPaged()) return this._getRangePaged(start, end, ignoreCache, fetchNow); if (this.localData == null) { this.localData = []; // fetch the entire data-set var criteria = this.getServerFilter(); this.setRangeLoading(start, end); this.fetchRemoteData(criteria); } return this.localData.slice(start, end);},getAllRows : function () { if (!this.lengthIsKnown()) return []; return this.getRange(0, this.getLength());},// called by grids, allows dynamic derivation of values. Used in order to allow a ResultSet to// use a set of XML elements as its dataset.// "field" is the optional field descriptor used in the visual component. getFieldValue : function (record, fieldName, field) { return this.getDataSource().getFieldValue(record, fieldName, field);},// Retrieving rows// --------------------------------------------------------------------------------------------//> @method resultSet.lengthIsKnown()// Whether the ResultSet actually knows how many records are available from the server.// The ResultSet will not know how many records are available when initially fetching and // filtering data. Note that the value returned from +link{resultSet.getLength()} will be // an arbitrary, large value if the actual length is not known.// @return (boolean) whether length is known// @visibility external//<lengthIsKnown : function () { // for a paged RS, totalRows remains null until you call setFullLength() // for a local or basic RS we never know the total length until fetch() returns return this.localData != null && (this.isPaged() ? this.totalRows != null : this._fetchingRequest == null);},//> @method resultSet.rowIsLoaded() [A]// Whether the given row has been loaded.// <p>// Unlike get(), will not trigger a server fetch. //// @param rowNum (number) row to check// @return (boolean) true whether if the given row has been loaded, false if it has not been// loaded or is still in the process of bring loaded// @visibility external//<rowIsLoaded : function (rowNum) { if (this.localData != null) { var row = this.localData[rowNum]; if (row != null && !Array.isLoading(row)) return true; } return false;},//> @method resultSet.rangeIsLoaded() [A]// Whether the given range of rows has been loaded.//// Unlike getRange(), will not trigger a server fetch. //// @param startRow (number) start position, inclusive// @param endRow (number) end position, exclusive// @return (boolean) true if all rows in the given range have been loaded, false if any rows in// the range have not been loaded or are still in the process of being loaded// @visibility external//<rangeIsLoaded : function (startRow, endRow) { if (this.localData == null) return false; for (var i = startRow; i < endRow; i++) { var row = this.localData[i]; if (row == null || Array.isLoading(row)) return false; } return true;},// get the index of the last cached row after rowNum, or null if rowNum itself is not cached.// "reverse" parameter searches backwardsfindLastCached : function (rowNum, reverse) { if (!this.rowIsLoaded(rowNum)) return null; if (reverse) { for (var i = rowNum; i >= 0; i--) { var row = this.localData[i]; if (row == null || Array.isLoading(row)) break; } return i + 1; } else { var length = this.getLength(); for (var i = rowNum; i < length; i++) { var row = this.localData[i]; if (row == null || Array.isLoading(row)) break; } return i - 1; }},// get the index of the first and last cached row around rowNum, or null if rowNum itself is// not cached.getCachedRange : function (rowNum) { // default to the last requested range, or zero if (rowNum == null) rowNum = this.lastRangeStart; if (rowNum == null) rowNum = 0; // no cache around this row if (!this.rowIsLoaded(rowNum)) return null; var length = this.getLength(); if (this.allMatchingRowsCached()) return [0, length-1]; var startIndex = this.findLastCached(rowNum, true), endIndex = this.findLastCached(rowNum); return [startIndex, endIndex];},//> @method resultSet.setRangeLoading() // Initializes null data in the specified range to Array.LOADING// // @param start (number) start position// @param end (number) end position// @visibility internal//<setRangeLoading : function (start, end) { for (var i = start; i < end; i++) { if (this.localData[i] == null) this.localData[i] = Array.LOADING; }},// given an array, set all null values to the "loading" marker and fill out the array to the// length specified.fillRangeLoading : function (arr, length) { for (var i = 0; i < length; i++) { if (arr[i] == null) arr[i] = Array.LOADING; } return arr;},
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -