Hi All,
This is my first attempt at coding JavaScript in a OOP way. I get the following error not sure why:
SCRIPT5009: 'iceCreamApp' is undefined
$(document).ready(function() {
//Create name space so their will be no collisions if application grows
var iceCreamApp = {};
iceCreamApp.Truck = new Array();
//Load data from list into array right away
(function() {
//IIFE() Imediately Invoked Function
var url = "http://isaac.issharepoint.com/demo/_vti_bin/listdata.svc/IceCreamTrucks?$select=State,TownName,CountyName,IceCreamTrucks";
$.ajax({
url:url,
type:"GET",
dataType:"json",
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function(data) {
//console.log(data.d);
success(data);
},
error: function(data) {
//failure(data);
//console.log("ERROR");
}
})
function success(data)
{
var iceCreamTrucks = data.d.results;
for(var i = 0; i<iceCreamTrucks.length; i++)
{
iceCreamApp.Truck.push(new ICIItem({State:iceCreamTrucks[i].State,
TownName:iceCreamTrucks[i].TownName,
CountyName:iceCreamTrucks[i].CountyName,
TruckCnt:iceCreamTrucks[i].IceCreamTrucks}));
}
}
}());
})
function ICIItem(params)
{
this.TruckCnt = params.TruckCnt;
if (this.TruckCnt > 5)
{
//do something
}
this.State = params.State;
this.TownName = params.TownName;
this.CountyName = params.CountyName;
};
ICIItem.prototype.getUniqueType = function(Type)
{
//This array will hold the unique states from the main array.
var uniqueType = [];
//loop through Array
for (var i=0; i<iceCreamApp.Truck.length; i++) //<-- SCRIPT5009: 'iceCreamApp' is undefined
{
//if current item in array does not exist in my 'uniqueType' array, add it to 'uniqueType' array.
if (($.inArray(iceCreamApp.Truck[i], uniqueType)) === -1)
{
uniqueType.push(iceCreamApp.Truck[i]);
}
}
return uniquType;
}
ICIItem.prototype.getjQplotArray = function(uArray)
{
var jqPlotDataArray = [];
for(var i=0; i<uArray.lenght; i++)
{
var jqPlotData = {};
jqPlotData.Type = uArray[i];
jqPlotData.Count = 0;
for (var x=0; x<iceCreamApp.Truck.length; x++)
{
if(uArray[i] == iceCreamApp.Truck[x])
{
jqPlotData.Count++;
}
}
jqPlotDataArray[i] = jqPlotData;
}
return jqPlotDataArray;
};
function selectQry(list)
{
var qryVal = list.options[list.selectedIndex].value;
var uniqueTypeArray = ICIItem.prototype.getUniqueType(qryVal);
var getChartData = ICIItem.prototype.getjQplotArray(uniqueTypeArray);
plotJqChart(getChartData);
}
function plotJqChart(myData)
{
var plot1 = jQuery.jqplot('chart1',[myData], {
seriesDefaults: {
renderer: jQuery.jqplot.PieRenderer,
rendererOptions: {
showDataLabels: true
}
},
legend: { show:true, location: 'e' }
});//end plot1
}
Open in new window
Look at Line 60