This article introduces the HTML5 Address Book to obtain the specified number of personal information, as follows:
one, get more personal information : To solve the address book to import more personal information, to solve the access to more than one person's information. I use plus.contacts.getAddressBooK and Address.find to put the ID and displayName of all the contacts in the Address Book Get it out and then show it by getting the page from your own address book.
1, to solve this problem first of all you have to write a JS address book, so that you can separate all your contacts, and next to jump to the first letter you want.
2, resolve to obtain all contact information
Plus.contacts.getAddressBook (Plus.contacts.addressbook_phone,function (addressbook) {//Get Address Book information
Address Book operations via AddressBook
Addressbook.find (Null,function (contacts) {
Varusername =newarray ();
Varlinklist =newlinkedlist ();
if (Contacts.length > 0) {//Get all the people in the current address book
for (vari = 0; i < contacts.length i) {
Username[i] = contacts[i].displayname "-" contacts[i].id;//connection ID and username, for later filtering most prepared
The following code is to classify the information of all the contacts, which involves writing the JS page code
linklist = sortpy (username);//To classify the number of contact groups
Createlicheckbox (linklist);//category information displayed to the page, I use a checkbox for multiple contact selection
Alert ("Find contact Error:" e.message);
|
second, from the Address Book to import multiple selected personal information : To solve this problem in the previous creation of the Address Book page, you must put the contact ID on the page (using display hidden), so I get the selected checkbox , you can get the IDs directly and put them in an array. The contact information for these IDs is then filtered through the Plus.contacts.getAddressBook and address.find formats.
1, to solve the use of checkbox to get contact ID, here I use JQuery.
$ (" input:checked "). each (function () {
varindex = $ (this). Parent (). Prev (). Children (' label '). Text ()//Get ID
varname = $ (this). Parent (). Prev (). Children (' P '). Text ()://Get name
Div class= "line number5 index4 alt2" > Username.push (name);
usernameindex.push (index);
});
|
2, to solve the index into find inside the filter information, the specific ID below the contact information to take out
Plus.contacts.getAddressBook (Plus.contacts.addressbook_phone,function (addressbook) {//Get Address Book information
for (Varj = 0; J < Username.length J) {//loop selected contacts, remember the loop must be put here, at first I put it outside the Plus.contacts.getAddressBook is wrong
Addressbook.find (Null,function (contacts) {
Console.log ("Enter query");
for (vari = 0; i < contacts.length i) {//Whether it is more than one information, be sure to loop the array
Console.log ("Enter the Cycle");
Vardisplayname = Contacts[i].displayname;
if (Contacts[i].phonenumbers.length > 0) {///Here you need to judge whether it is empty, empty array without index=0;
Phone = Contacts[i].phonenumbers[0].value;
Phone = contacts[i].phonenumbers;
if (Contacts[i].emails.length > 0) {///Here you need to judge whether it is empty, empty array without index=0;
emails = Contacts[i].emails[0].value;
emails = contacts[i].emails;
Vardatenum =newdate (Contacts[i].birthday);//The Birthday here is number type!!! Official Handbook, Pit Dad?
Dates = Datenum.getfullyear () "." (Datenum.getmonth () 1) "." Datenum.getdate ();
Remark = Contacts[i].note;
Vargetcontact = {//Put all the information in a JSON
Here is my code of business, where everyone can write their own information
Insertcontact (DB, getcontact); Multiple information inserts a thread security problem appears!!!!!!!
Console.log (username.length);
Console.log ("Query Error");
The screening here is very important!!! So we can pick up the matching information.
Console.log ("Open Address Book error");
|