New Matrix methods :
Contributed by Tony Lefebvre
New Matrix methods
jsx3.gui.Matrix.prototype.each = function(strXPathPredicate, fctYield) { var iteRecord = cdfDocument.selectNodeIterator('//record[' + strXPathPredicate + ']') var iIndex = 0; while (iteRecord.hasNext()) { var rnCurrent = iteRecord.next(); fctYield(this, rnCurrent, iIndex++) } } /** * Creates a new array using the mapped values of each record in this matrix * that matches the XPath predicate <code>strXPathPredicate</code>. * <code>fctMap</code> is called for each record in this matrix and the * matrix object, record node and the index are passed as the argument. * The new array is constructed with the return values of each call to <code>fctMap</code>. * @param fctMap {Function} * @return {jsx3.$Array} */ jsx3.gui.Matrix.prototype.map = function(strXPathPredicate, fctMap) { var iteRecord = this.getXML().selectNodeIterator('//record[' + strXPathPredicate + ']') var iIndex = 0; var arrResult = jsx3.$A(); while (iteRecord.hasNext()) { var rnCurrent = iteRecord.next(); arrResult.push(fctMap(this, rnCurrent, iIndex++)) } return arrResult } jsx3.gui.Matrix.prototype.map2 = function(strXPathPredicate, fctMap) { return jsx3.$A(this.selectNodes(strXPathPredicate)).map(fctMap) } jsx3.gui.Matrix.prototype.eachChecked = function(fctYield) { this.each('@checked=1', fctYield) } jsx3.gui.Matrix.prototype.getCheckedRecordIds = function() { return this.map('@checked=1', function(mtxMyMatrix, rnMyRecordNode, iIndex) { return rnMyRecordNode.getAttribute('jsxid') }) }
Usage:
myAPP.APP.getJSXByName("mtxEod").eachChecked(function(mtxMyMatrix, rnMyRecordNode, iIndex) { jsx3.log('record node jsxtext=' + rnMyRecordNode.getAttribute('jsxtext') + ' is checked') }) myApp.APP.getJSXByName("mtxEod").getCheckedRecordIds()

Comments (2)
Jul 21, 2010
Darren Hwang says:
Maybe these belong to the CDF class instead of Matrix. Why is there 2 jsx3.gui...Maybe these belong to the CDF class instead of Matrix.
Why is there 2 jsx3.gui.Matrix.prototype.map functions?
Jul 22, 2010
Tony Lefebvre says:
1) Yes, these should belong to the CDF class. However I didn't figured out how t...1) Yes, these should belong to the CDF class. However I didn't figured out how to 'update' the Matrix prototype from the modified CDF prototype after it has been already loaded (for example, when using the GI Max build)
2) renamed the second map to map2 (it is doing exactly the same, but maybe less efficient)