HTML5 Address Book access to specify multiple personal information method analysis

Source: Internet
Author: User
Tags prev

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
Linklist.show ();
Createlicheckbox (linklist);//category information displayed to the page, I use a checkbox for multiple contact selection
}
},function (e) {
Alert ("Find contact Error:" e.message);
});
},function (e) {
});

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");
var id = contacts[i].id;
Vardisplayname = Contacts[i].displayname;
Varphone = "";
Varemails = "";
Vardates = "";
Varremark = "";
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;
}else{
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;
}else{
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
Contactname:displayname,
Sex: "",
Department: "",
Positions: "",
Tel: "",
Phone:phone,
Email:emails,
Birthday:dates,
Hobby: "",
Remark:remark
};
Here is my code of business, where everyone can write their own information
Createcontacttable (DB);
Insertcontact (DB, getcontact); Multiple information inserts a thread security problem appears!!!!!!!
}
Console.log (username.length);
},function (e) {
Console.log ("Query Error");
}, {
The screening here is very important!!! So we can pick up the matching information.
Filter: [{
Logic: "or",
Field: "id",
VALUE:USERNAMEINDEX[J]
}],
Multi:false
});
}
},function (e) {
Console.log ("Open Address Book error");
});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.