I have the following code within a JavaScript dynamic action in Oracle APEX v4.2 to work with JSON, i.e.:
var graph_data = $v('P780_GRAPH_DATA');
var rule_data = $v('P780_RULE_DATA');
var unique = function(origArr) {
var newArr = [],
origLen = origArr.length,
found, x, y;
for (x = 0; x < origLen; x++) {
found = undefined;
for (y = 0; y < newArr.length; y++) {
if (origArr[x] === newArr[y]) {
found = true;
break;
}
}
if (!found) {
newArr.push(origArr[x]);
}
}
return newArr;
}
var accessLines = graph_data.filter(function (line) {
return !isTrunkLine(line);
});
var trunkLines = graph_data.filter(isTrunkLine);
accessLines.forEach(drawLine);
trunkLines.forEach(drawLine);
function isTrunkLine(intf_type) {
var purpose = intf_type.purpose;
return purpose === 'TRUNK';
}
When working with this outside of Oracle APEX but just in a separate HTML file that contains the javascript code, all works fine but now having to move this into Oracle APEX, I am getting the following error:
Uncaught TypeError: graph_data.filter is not a function
Unsure what I am doing wrong but I basically have a valid JSON object within graph_data as I have run it through JSONLint but not sure what the issue is here.
$v('P780_GRAPH_DATA')return? It should be an array.