I am working on a page that showcases graphs based on selected criteria. Each graph requires its own object reference, and I am creating new objects within a for loop. However, I'm facing the challenge of accessing those objects outside of that specific function.
var chartObject = new Array();
function runInit () {
$(document).ready(function(){
$("#submit").click(function() {
$("#pointList :selected").each(function(){
selectedValues.push($(this).val());
});
for(var j = 0; j < selectedValues.length; j++)
{
chartObject[j] = new Object();
var charts = [];
charts.push( drawDataView( demos[demo] ) );
chartObject[j].allDataLoaded = function( ) {
//more code
};
}
});
});
}
I now need to utilize chartObject[j]
in another function:
function drawDataView ( demo ) {
var dataCache = new DataCache( chartObject[j], dataSource );
}
However, as j
is not defined in drawDataView
, I am at a loss on how to create new objects within the for-loop and still use the variable elsewhere.
If you have any suggestions, they would be greatly appreciated!