I have a page that displays graphs based on the selected criteria. Each graph is a separate instance and needs its own object reference. I have new objects being created within the for loop but how can I access those objects outside that particular 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 need to use chartObject[j] in another function:
function drawDataView ( demo ) {
var dataCache = new DataCache( chartObject[j], dataSource );
}
Obviously j isn't defined in drawDataView, so how can I create new objects within that for-loop and use the variable elsewhere?
Any suggestion is appreciated!