Page 1 of 1
contacts service call and data manipulation
Posted: Tue Feb 11, 2014 3:12 am
by Abdelrahim
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?
contacts service call and data manipulation
Posted: Tue Feb 11, 2014 4:29 am
by Illya Stepanov
Hi -
Can you please post the complete JS code that you using?
contacts service call and data manipulation
Posted: Wed Feb 12, 2014 1:53 am
by Abdelrahim
For some reason my text gets truncated so I added an image. After calling the contacts service I execute the following Javascript:
contacts service call and data manipulation
Posted: Wed Feb 12, 2014 12:03 pm
by Maryna Brodina
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?
contacts service call and data manipulation
Posted: Wed Feb 12, 2014 3:58 pm
by Kateryna Grynko
Hi,
Try this code please:precodevar Numbers = [];
for (var i=0; i<data.length; i++) {
var phoneNumbers = data.phoneNumbers;
if(phoneNumbers) {
for (var j=0; j<phoneNumbers.length; j++) {
var phone = phoneNumbers[j].value;
Numbers.push(phone);
}
}
}
localStorage.setItem("Numbers", JSON.stringify(Numbers));/code/pre
contacts service call and data manipulation
Posted: Thu Feb 13, 2014 12:14 am
by Abdelrahim
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
contacts service call and data manipulation
Posted: Thu Feb 13, 2014 3:54 pm
by Kateryna Grynko
Hi Abdelrahim,
To save an object in localStorage you should first convert it to string using codeJSON.stringify/code