Abdelrahim
Posts: 0
Joined: Sat Nov 30, 2013 3:31 am

contacts service call and data manipulation

I am trying to manipulate data returned from a contacts service call. I want to filter out only the phone numbers and store them in a local variable as and array. I use the following code
var Contacts=[];
var Numbers=[];

for (var i=0; i,Numbers);

which is a modification of the code I got from http://docs.phonegap.com/en/2.4.0/cor...

When I place an alert in the code it displays the data as I expect it to be stored but when I try the code on phone my program just hangs. Am I doing something wrong?

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

contacts service call and data manipulation

Hi -

Can you please post the complete JS code that you using?

Abdelrahim
Posts: 0
Joined: Sat Nov 30, 2013 3:31 am

contacts service call and data manipulation

For some reason my text gets truncated so I added an image. After calling the contacts service I execute the following Javascript:
Image

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

contacts service call and data manipulation

Hello! Could you clarify when exactly it stops working? Are there any alerts if you don't comment alert(row2) line? On what event you invoke service? On what event did you add this code?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

contacts service call and data manipulation

Hi,

Try this code please:precodevar Numbers = [];
for (var i=0; i<data&#46;length; i++) {
var phoneNumbers = data&#46;phoneNumbers;
if(phoneNumbers) {
for (var j=0; j<phoneNumbers&#46;length; j++) {
var phone = phoneNumbers[j]&#46;value;
Numbers&#46;push(phone);
}
}
}
localStorage&#46;setItem("Numbers", JSON&#46;stringify(Numbers));/code/pre

Abdelrahim
Posts: 0
Joined: Sat Nov 30, 2013 3:31 am

contacts service call and data manipulation

Hi Katya,

Your codes works, thank you very much. If it is not too much trouble can you tell me what was wrong in my code. If it is a long explanation don't worry about it.

Regards

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

contacts service call and data manipulation

Hi Abdelrahim,

To save an object in localStorage you should first convert it to string using codeJSON&#46;stringify/code

Return to “Issues”