Solved

Issue With the Javascript Arrays

Posted on 2014-11-12
3
119 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

911 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

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now