So, What is the problem ? The problem with it is my contacts having the email accounts.So email doesn't have the phonenumber.
Here is the screenshot : http://prntscr.com/82meyr
What is the issue ?
Well, the problem is that when it encounters the email the for loop stops immediately and shows the 20-30 contacts only!
function onSuccess(contacts)
{
for (var i=0; i);
}
}
My code :
http://stackoverflow.com/questions/31...
Is there any way to bypass the email accounts ?
Thank you!
- 48 Posts
- 0 Reply Likes
Posted 5 years ago
Petra V., Champion
- 7794 Posts
- 1391 Reply Likes
Simply check for null-value of phonenumbers (NOT an empty array!). If null, then don't look for phonenumbers[0].
- 48 Posts
- 0 Reply Likes
function onSuccess(contacts) {
alert("Total contacts = "+ contacts.length);
for (var i=0; i<contacts.length; i++)
{
if(contacts[i].phoneNumbers[0].value !== null)
{
// console.log("Display Name = " + contacts[i].phoneNumbers[0].value);
$('#contactList').append("<li><a href='#'><h2>"+ contacts[i].displayName +"</h2><p>" + contacts[i].phoneNumbers[0].value + "</p></a></li>");
}
$('#contactList').listview("refresh");
}
}
Still same error!
Petra V., Champion
- 7794 Posts
- 1391 Reply Likes
You can not evaluate phonenumbers[0], because it does not exist.
Why don't you just display the full contents of the contacts object for test purposes? You would immediately see what you got returned, and how to loop through the object.
- 48 Posts
- 0 Reply Likes
Is that correct ?
function onSuccess(contacts) {
alert("Total contacts = "+ contacts.length);
for (var i=0; i<contacts.length; i++)
{
for(var j=0; j<contacts[i].phoneNumbers.length;j++)
{
$('#contactList').append("<li><a href='#'><h2>"+ contacts[i].phoneNumbers[j].value + "</h2></a></li>");
}
}
$('#contactList').listview("refresh");
}
Petra V., Champion
- 7794 Posts
- 1391 Reply Likes
- do you only want to store phone numbers, or full contacts records, including all other fields?
- how and when do you want to retrieve these data?
- how critical is synchronization with your remote database?
- did you display the full contacts object for test purposes? Have you corrected the errors above?
- is this a homework assignment?
- 48 Posts
- 0 Reply Likes
Anyway, What I want to do is, I want to get the contact number(mobile) and want to check on the mysql database using POST method. If that exists then it will show all the details of the database and it will store it in the local database. Contacts name and phone number will be stored from the local contact list, rest will be stored from the JSON result.
Petra V., Champion
- 7794 Posts
- 1391 Reply Likes
I ask, because redundant database synchronization is a tough task to get right. Perhaps other options, like retrieving remote data just in time when needed, would be a better fit. You would then not have anything redundant, and the displayed data would always be current values.
If, however, this is just an exercise for you, I would think that you learn most by exploring different application options yourself, then research the plugin documentation.
Petra V., Champion
- 7794 Posts
- 1391 Reply Likes
- 48 Posts
- 0 Reply Likes
Petra V., Champion
- 7794 Posts
- 1391 Reply Likes
2. Since you are storing data locally, what if the user has multiple devices? What if the contacts of these devices are not identical?
Can your UserABC have two devices with different Google accounts, different contacts and still be one user in your database?
3. Your two tables seem utterly redundant. Isn't the fact that a user exists merely an attrbute of the entity 'user'? Once a user exists, you should just set that attribute to true.
4. Suppose you delete a phonenumber from the nysql database, how and when would it be deleted from the device?
- 48 Posts
- 0 Reply Likes
function onSuccess(contacts)
{
for(var i=0;i<contacts.length;i++)
{
if(contacts[i].phoneNumbers)
{
for (var j = 0; j < contacts[i].phoneNumbers.length; j++)
{
$('#contactList').append("<li><a href='#'><h2>"+ contacts[i].displayName +"</h2><p>" + contacts[i].phoneNumbers[0].value + "</p></a></li>");
}
}
}
Petra V., Champion
- 7794 Posts
- 1391 Reply Likes
Have you displayed the full contacts object for test purposes now, so you can actually SEE what you're doing?
- 48 Posts
- 0 Reply Likes
Petra V., Champion
- 7794 Posts
- 1391 Reply Likes
And even if I had it, I could probably not see its application architecture or data model.
Can you?
- 48 Posts
- 0 Reply Likes
That's it.
- 48 Posts
- 0 Reply Likes
Petra V., Champion
- 7794 Posts
- 1391 Reply Likes
JesseMonroy650 (Volunteer), Champion
- 3325 Posts
- 122 Reply Likes
I see at least 6 posts for this request (in 24 hours), between stackoverflow and here (2). I suspect all the same OP.
@Abhishek,
Working code that compiles on Phonegap Build
https://github.com/jessemonroy650/Phonegap-Contact-Test
Jesse
Petra V., Champion
- 7794 Posts
- 1391 Reply Likes
Since I don't follow any stackoverflow threads, I didn't know about the others.
I wonder why the OP would do such a thing. It's not of his advantage, is it?
Abhishek, can you clarify, please?
- 48 Posts
- 0 Reply Likes
Petra V., Champion
- 7794 Posts
- 1391 Reply Likes
However, if this thread has helped you to understand the implications of your requirements, that's a good result.
And surely, if your aim was to learn, it's way better to do it by yourself.
- 48 Posts
- 0 Reply Likes
Petra V., Champion
- 7794 Posts
- 1391 Reply Likes
Then please show me where you said "it's duplicating code".
(The only thing about 'duplicating' I can find is about the same phone number multiple times, and I gave you the cause for that immediately: it was your javascript error, where you hard-coded the display of phoneNumbers[0].)
- 2 Posts
- 0 Reply Likes
http://phonegapcmsworld.blogspot.in/2...
JesseMonroy650 (Volunteer), Champion
- 3325 Posts
- 122 Reply Likes
- 2 Posts
- 0 Reply Likes
Related Categories
-
Programming (Others)
- 1167 Conversations
- 23 Followers



