View Source

New Matrix methods :
Contributed by Tony Lefebvre

{code:JavaScript|title=New Matrix methods|borderStyle=solid}
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')
})
}
{code}

Usage:
{code}
myAPP.APP.getJSXByName("mtxEod").eachChecked(function(mtxMyMatrix, rnMyRecordNode, iIndex) {
jsx3.log('record node jsxtext=' + rnMyRecordNode.getAttribute('jsxtext') + ' is checked')
})
myApp.APP.getJSXByName("mtxEod").getCheckedRecordIds()
{code}