Solved

Issue With the Javascript Arrays

Posted on 2014-11-12
3
123 Views
Last Modified: 2014-11-16
Hi,

I have attached the script. What I am trying to do is specified in the comments in the script.

Below are the comments that I specified in the script.

     //check if the pre-built  dashboard items array has a projectdesc that matches the projectName and then build the table row by passing Project Name and projectURL, projectstatuslabel to the getProjectRow function

//Here how do I iterate through dashboard items array to check if there is a matching projectdesc whose string value is equal to ProjectName inside this for loop?

i need to iterate through the dashboard array and find a matching description of the value in the for loop and then get the remaining properties of the object.

Please let me know if this is not clear.
script-2.txt
script-2.txt
0
Comment
Question by:Techsavy
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
vr6r earned 500 total points
ID: 40438327
Updated and commented the For loop from your script, give this a try:

for (var i = 0; i < data.d.results.length; i++) {
	var projectName = data.d.results[i].Title;
	var projectURL = data.d.results[i].ProjectURL;

	//set matcheditem var to array of dasboardItems objects filtered by matching projectdesc to projectName
	var matcheditem = $.grep(dashboardItems, function(n){
		return n.projectdesc == projectName;
	});
	
	//check length of resulting matcheditem array from above.
	//if > 0, call getProjectRow using first item in matcheditem array.
	if(matcheditem.length > 0) {
		getProjectRow(projectName, projectURL, matcheditem[0].projectstatuslabel);
	}
	
}

Open in new window


Hope that helps.
0
 

Author Comment

by:Techsavy
ID: 40439109
Thank you ..I will give this a try...
0
 

Author Closing Comment

by:Techsavy
ID: 40446019
Thank you. Worked like a charm!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question