For more information, see HTML5 address book.

Source: Internet
Author: User

For more information, see HTML5 address book.

This topic describes how to use the HTML5 address book to obtain the information of multiple users:

1. obtain the information of multiple people: before importing the information of multiple people in the address book, obtain the information of multiple people. I use plus. contacts. getAddressBook and address. find to obtain the IDs and displaynames of all contacts in the address book, and then display them on the get page through the address book I wrote.

1. To solve this problem, you first need to write a js address book by yourself, so that you can separate the first letter of all your contacts and jump to the first letter next to it.

2. Obtain all contact information

Plus. contacts. getAddressBook (plus. contacts. ADDRESSBOOK_PHONE, function (addressbook) {// Obtain Address Book information // you can use addressbook to perform address book operation addressbook. find (null, function (contacts) {var username = new Array (); var LinkList = new vertex list (); if (contacts. length> 0) {// obtain all persons in the current address book for (var I = 0; I <contacts. length; I) {username [I] = contacts [I]. displayName "-" contacts [I]. id; // connection id and username, which are the most prepared for filtering.} // The following Code classifies the information of all contacts, this involves the JS Page code LinkList = sortPY (username) written by myself; // classifies the contact array // LinkList. show (); createLiCheckBox (LinkList); // The category information is displayed on the page. I use checkBox to select multiple contacts }}, function (e) {alert ("Find contact error: "e. message) ;}) ;}, function (e ){});

2. Import multiple selected personal information from the address book: To solve this problem, you must place the contact id on the page when creating the address book page (hide with display ), in this way, when I obtain the selected checkBox, I can directly obtain the id and put the id in an array. Then, use plus. contacts. getAddressBook and address. find to filter out the contact information of these IDs.

1. Solve the Problem of using checkBox to get the contact id. Here I use JQuery.

// Filter the selected checkbox $ ("input: checked "). each (function () {var index = $ (this ). parent (). prev (). children ('label '). text (); // get id var name = $ (this ). parent (). prev (). children ('P '). text (); // get username. push (name); usernameIndex. push (index );});

2. Put these indexes in find to filter information and take out the contact information under a specific id.

Plus. contacts. getAddressBook (plus. contacts. ADDRESSBOOK_PHONE, function (addressbook) {// Obtain Address Book information for (var j = 0; j <username. length; j) {// The contacts selected by the loop. Remember to place the loop here. I put it in plus at the beginning. contacts. getAddressBook is out of error addressbook. find (null, function (contacts) {console. log ("Enter query"); for (var I = 0; I <contacts. length; I) {// no matter whether there are multiple pieces of information, you must loop through the array console. log ("Enter loop"); // var id = contacts [I]. id; var displayname = contact S [I]. displayName; var phone = ""; var emails = ""; var dates = ""; var remark = ""; if (contacts [I]. phoneNumbers. length> 0) {// check whether it is null. The empty array does not contain index = 0; phone = contacts [I]. phoneNumbers [0]. value;} else {phone = contacts [I]. phoneNumbers;} if (contacts [I]. emails. length> 0) {// check whether it is null. The empty array does not contain index = 0; emails = contacts [I]. emails [0]. value;} else {emails = contacts [I]. emails;} var dateNum = ne W Date (contacts [I]. birthday); // The birthday here is of the number type !!! Official manual? Dates = dateNum. getFullYear ()". "(dateNum. getMonth () 1 )". "dateNum. getDate (); remark = contacts [I]. note; var getContact = {// put all the information in a json file. contactName: displayname, sex: "", department: "", positions: "", tel :"", phone: phone, eMail: emails, birthday: dates, holobby: "", remark: remark}; // The following is my business code, here you can write your own information // createContactTable (db); // InsertContact (db, getContact); // thread-safe insertion of Multiple Information !!! !!!!} // Console. log (username. length) ;}, function (e) {console. log ("query error") ;},{// this filtering is very important !!! In this way, the matching information filters: [{logic: "or", field: "id", value: usernameIndex [j]}], multi: false });}}, function (e) {console. log ("Opening Address Book error ");});

With the above code, you can get the information of multiple contacts. You can try it. I hope it will be helpful for everyone's learning, and I hope you can support the house of helping customers more.

Related Article

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.