Solved

Javascript Push() and value access

Posted on 2014-02-26
5
432 Views
Last Modified: 2014-02-28
Hi,

Can someone check and see if the following javascript is correct?  I am trying to push values from a sharepoint list into a multidimensional array but I think I might be doing something wrong when I try to access.  I get an error due to the .each() and when I take it out, the error goes away.  The error says I'm missing a ")"

var anArray = new Array();


$().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "Analyst",
	CAMLViewFields: "<ViewFields><FieldRef Name='Title'></FieldRef></ViewFields>",
	CAMLQuery: "<Query><OrderBy><FieldRef Name='Title' /></OrderBy></Query>",
    completefunc: function (xData, Status) {
	//alert(xData.responseXML.xml);
      $(xData.responseXML).SPFilterNode("z:row").each(function() { 


			anArray.push({
				Analyst: $(this).attr("ows_Title"),
				Count:	 0
				});			
				


      });
     }
  }); 


   //Am I accessing the values to my array correctly
   $.each(anArray, function (index, value) {																													
        dataAn.addRow([anArray[index].Analyst, Number(anArray[index].Count]));
    }); 

Open in new window

0
Comment
Question by:Isaac
  • 3
  • 2
5 Comments
 
LVL 9

Expert Comment

by:Sar1973
ID: 39891322
I think you're missing a parenthesis...try each(function()) and see http://www.w3schools.com/Php/func_array_each.asp
0
 
LVL 5

Author Comment

by:Isaac
ID: 39891685
I am using jquery not php
0
 
LVL 9

Expert Comment

by:Sar1973
ID: 39891798
Then you maybe have inserted } instead of }); at line 23.
0
 
LVL 5

Author Comment

by:Isaac
ID: 39891959
I'm using notepad and all of my braces and parenthesis have their open and close.

Is this right?
alert(anArray[x].Count);

What's the proper syntax to get the value of that kind of an array?
0
 
LVL 9

Accepted Solution

by:
Sar1973 earned 500 total points
ID: 39892053
anArray[x] is the right syntax to get the x-element of the array, while anArray.length will return the number of elements in the array.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
date format angularjs2 16 36
JDeveloper 12c for 32 bit 4 34
SharePoint sub-site searching and results. 8 20
angularls and plnkr 14 17
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.
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 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)
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…

707 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

12 Experts available now in Live!

Get 1:1 Help Now