About Contact Plugin

* Id is readonly, can't be set on adding

* Only support remove by Id

* DisplayName can't be set and read

* Sth special to set phone number

function addContact(){
//    navigator.contacts.create({"displayName":"Alex"});
    var rec = navigator.contacts.create();
    rec.id = "1";
    rec.displayName = "Alex";
    rec.nickname = "nickName";
    rec.birthday = "1978-01-01";
    var phone = [];
    phone[0] = new ContactField("work","12312341234", false);
    phone[1] = new ContactField("mobile","13312341234", true);
    phone[2] = new ContactField("home",  "13312341234", false);
    rec.phoneNumbers = phone;

    rec.name = new ContactName();
    rec.name.givenName = "givenName";
    rec.name.familyName = "familyName";
    rec.note = "Sample contact of Alex";
    rec.save(function(rec){showInfo(showContactInfo(rec))}, showInfo);
}

 

function showContactInfo(rec){
    var s=rec.id+" displayName:"+rec.displayName;
    if(rec.name){
        s +=" "+rec.name.familyName+" "+rec.name.givenName+" "+rec.name.middleName+" ";
        
    }
    if(rec.phoneNumbers){
        s += " phone";
        for(var j=0; rec.phoneNumbers[j]; j++){
            s += " "+rec.phoneNumbers[j].type+":"+rec.phoneNumbers[j].value+" ";
        }
    }
    s += "\n";
    return s;
}

 

你可能感兴趣的:(About Contact Plugin)