Isaac
asked on
JSON error
I get the error,
Message: Object doesn't support this property or method
I got the idea from this site
http://bateru.com/news/2012/03/code-of-the-day-get-unique-objects-from-an-array-of-json-objects/
Message: Object doesn't support this property or method
function buildProjExecution(chartTy<wbr ></wbr>pe) {
alert("chartType: "+chartType);
getProjects();
//var ProjectItem = []; // Initializes the array
arrProjs = _.uniqObject(arrProjs,true<wbr ></wbr>);
//arrProjs = _.uniq(['ACGY20137912PB','<wbr ></wbr>ACGY201379<wbr ></wbr>12PB','ACG<wbr ></wbr>Y20137912P<wbr ></wbr>B','ACGS20<wbr ></wbr>135001-1',<wbr ></wbr>'ACGS20135<wbr ></wbr>001-1','AC<wbr ></wbr>GS20135001<wbr ></wbr>-2']);
$.each(ProjectDataArray, function (index, value) {
alert(index + ':' + value);
});
alert("Prog Num: "+arrProjs.length); //<-- 20 values here also after the uniq()
}
//Get values into an array so I can use the _.uniq() to remove the duplicates so I can add funding amount
function getProjects() {
var fiscalYear = (new Date).getFullYear();
var prevYear = fiscalYear - 1;
beginFY = prevYear + "-10-01"; // 2012-10-01
endFY = fiscalYear + "-09-30"; // 2013-09-30
var i=0;
$().SPServices({
operation: "GetListItems",
listName: "ER_Projects",
async: false,
CAMLViewFields: "<ViewFields><FieldRef Name='ProjectNumber'></Fie<wbr ></wbr>ldRef><Fie<wbr ></wbr>ldRef Name='AmountProjected'></F<wbr ></wbr>ieldRef></<wbr ></wbr>ViewFields<wbr ></wbr>>",
CAMLRowLimit: 20,
CAMLQuery: "<Query><Where><And><Geq><<wbr ></wbr>FieldRef Name='ObligationDate' /><Value IncludeTimeValue='TRUE' Type='DateTime'>"+beginFY+<wbr ></wbr>"</Value><<wbr ></wbr>/Geq><Leq><wbr ></wbr><FieldRef Name='ObligationDate' /><Value IncludeTimeValue='TRUE' Type='DateTime'>"+endFY+"<<wbr ></wbr>/Value></L<wbr ></wbr>eq></And><<wbr ></wbr>/Where></Q<wbr ></wbr>uery>",
completefunc: function (xData, Status) {
$(xData.responseXML).SPFil<wbr ></wbr>terNode("z<wbr ></wbr>:row").eac<wbr ></wbr>h(function<wbr ></wbr> () {
/*ProjectItem = new Object();
ProjectItem.projectNumber = $(this).attr("ows_ProjectN<wbr ></wbr>umber");
ProjectItem.amountProjecte<wbr ></wbr>d = $(this).attr("ows_AmountPr<wbr ></wbr>ojected");<wbr ></wbr>
ProjectDataArray[i] = ProjectItem;
i++;*/
var tempProject = new Object();
tempProject["ProjectNumer"<wbr ></wbr>] = $(this).attr("ows_ProjectN<wbr ></wbr>umber");
tempProject["AmountProject<wbr ></wbr>ed"] = $(this).attr("ows_AmountPr<wbr ></wbr>ojected");<wbr ></wbr>
arrProjs.push(tempProject)<wbr ></wbr>;
/*
var tempProject = new Object();
tempProject["ProjectNumer"<wbr ></wbr>] = $(this).attr("ows_ProjectN<wbr ></wbr>umber");
tempProject["AmountProject<wbr ></wbr>ed"] = $(this).attr("ows_AmountPr<wbr ></wbr>ojected");<wbr ></wbr>
arrProjs.push(tempProject)<wbr ></wbr>;*/
});
}
});
}
/*
@function _.uniqObjects
@require Underscore.js and json.stringify
@purpose return an array of objects without duplicated objects.
*/
_.uniqObjects = function( arr ){
return _.uniq( _.collect( arr, function( x ){
return JSON.stringify( x );
}));
};
I got the idea from this site
http://bateru.com/news/2012/03/code-of-the-day-get-unique-objects-from-an-array-of-json-objects/
ASKER
Yes, I dud
ASKER
did
ASKER
I also tried it this way but still get the same error:
Did I do this part correct?
function buildProjExecution(chartType) {
getProjects();
arrProjs = _.uniqObject(arrProjs,true);
$.each(ProjectDataArray, function (index, value) {
alert(index + ':' + value);
});
alert("Prog Num: "+arrProjs.length); //<-- 20 values here also after the uniq()
}
//Get values into an array so I can use the _.uniq() to remove the duplicates so I can add funding amount
function getProjects() {
var i=0;
$().SPServices({
operation: "GetListItems",
listName: "Project",
async: false,
CAMLViewFields: "<ViewFields><FieldRef Name='ProjNumber'></FieldRef><FieldRef Name='AmtProjected'></FieldRef></ViewFields>",
CAMLRowLimit: 20,
CAMLQuery: "<Query><Where><And><Geq><FieldRef Name='ObDate' /><Value IncludeTimeValue='TRUE' Type='DateTime'>"+beginFY+"</Value></Geq><Leq><FieldRef Name='ObligationDate' /><Value IncludeTimeValue='TRUE' Type='DateTime'>"+endFY+"</Value></Leq></And></Where></Query>",
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function () {
ProjectItem = new Object();
ProjectItem.projNumber = $(this).attr("ows_ProjNumber");
ProjectItem.amtProjected = $(this).attr("ows_AmtProjected");
ProjectDataArray[i] = ProjectItem;
i++;
});
}
});
}
/*
@function _.uniqObjects
@require Underscore.js and json.stringify
@purpose return an array of objects without duplicated objects.
*/
_.uniqObjects = function( arr ){
return _.uniq( _.collect( arr, function( x ){
return JSON.stringify( x );
}));
};
Did I do this part correct?
/*
@function _.uniqObjects
@require Underscore.js and json.stringify
@purpose return an array of objects without duplicated objects.
*/
_.uniqObjects = function( arr ){
return _.uniq( _.collect( arr, function( x ){
return JSON.stringify( x );
}));
};
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi,
sorry to bring this question to a different road, but I made some good experiences with another library: linq.js (http://linqjs.codeplex.com/)
I put up a sample here:
http://jsfiddle.net/EE_RainerJ/FCYFP/
(simply created an array with 3 distinct elements but added them multiple times).
Con of this library is that the documentation and samples are sometimes really pure, but the Linq syntax and the implemented functions look very promising and I was nearly always able to get to the point what I wanted.
HTH
Rainer
sorry to bring this question to a different road, but I made some good experiences with another library: linq.js (http://linqjs.codeplex.com/)
I put up a sample here:
http://jsfiddle.net/EE_RainerJ/FCYFP/
(simply created an array with 3 distinct elements but added them multiple times).
Con of this library is that the documentation and samples are sometimes really pure, but the Linq syntax and the implemented functions look very promising and I was nearly always able to get to the point what I wanted.
HTH
Rainer
ASKER
Sorry for the late response...I had to run some errands.
leakim971, I added the library before my script.
Rainer, wow! That seems very powerful. I'll give that a try also.
leakim971, I added the library before my script.
Rainer, wow! That seems very powerful. I'll give that a try also.
ASKER
Rainer,
Nothing happens when i try what you have in js fiddle....I don't even get any errors.
Some of my "ProjectedAmount" is blank. Maybe that's why. How do I check for undefined/blank with the linq?
Nothing happens when i try what you have in js fiddle....I don't even get any errors.
Some of my "ProjectedAmount" is blank. Maybe that's why. How do I check for undefined/blank with the linq?
ASKER
I get an error now.... It say "E is undefined"
ASKER
Do I need more than just "jquery.linq.min.js" library?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://underscorejs.org/
https://github.com/jashkenas/underscore