Search for contacts

Source: Internet
Author: User

To search on the contacts database, you can use the contacts. Find () method as follows:
Navigator. Contacts. Find (contactfields, onsuccess, onerror, options );

This example shows the following content:

1st parameters are used to pass a set of contact fields to the method. These fields are also returned. For example, if you want a personal name, email address, or phone number, you should specify it here. If you only want the contact ID, you can pass a null value to this parameter. If you want to return all fields, you can pass them to ["*"].

The 2nd parameters are the success callback function, which receives a correct contact object to save the contact information to be searched.

The first parameter is the error callback function, which will contain any errors thrown.

4th parameters are a set of options that can be passed to the find method. One of the most commonly used is the filter option, which is a string that can filter and query the contacts database.

The following is an example of finding the address book:
Function onsuccess (contacts ){
Document. Write (contacts. Length + 'contacts found .');
For (VAR I = 0; I <contacts. length; I ++ ){
For (var j = 0; j <contacts [I]. emails. length; j ++ ){
Document. Write ("email =" + contacts [I]. emails [J]. Email );
}
}
}

Function onerror (contacterror ){
Alert ('ooops! ');
}

// Search for all contacts with Gmail in the email address
VaR myoptions = new contactfindoptions ();
Myoptions. Filter = "Gmail ";
VaR myfields = ["emails"];
Navigator. Contacts. Find (myfields, onsuccess, onerror, myoptions );

 

Example 2:

$ ("# Page-contacts"). Live ("pageinit", function (){
VaR $ page = $ (this );
VaR fields = ["displayname", "phonenumbers", "Photos"];
Navigator. Contacts. Find (fields, function (contacts ){
Console. Log ("Address Book retrieved..." + contacts. Length );
VaR Results = [];
$. Each (contacts, function (I, c ){
Console. Log ("address book:" + C. displayname );
Results. push ("<li> <a href =''> });
$ (". Content-container", $ page). append (results. Join ("")). Listview ("refresh ");
}, Function (){
Alert ("An error occurred while searching the address book! ");
}, New contactfindoptions ());

});

Search for contacts

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.