function saveContact(contactObj) {
var contact = navigator.contacts.create();
var email = [1];
//var len = contactObj.phone.length;
var len = 2;
var phoneNums = [len];
email[0] = new ContactField("email",contactObj.email);
contact.email = email;
contact.nickname = contactObj.name;
contact.givenName = contactObj.name;
for (var i = 0; i < len; i++) {
phoneNums[i] = new ContactField(contactObj.phone[i].type, contactObj.phone[i].number, contactObj.phone[i].pref);
}
contact.phoneNumbers = phoneNums;
contact.save(onSaveSuccess, onSaveFail);
}
contactObj是一个包含姓名,电子邮件和电话号码列表的对象。代码命中onSaveSuccess并添加具有正确名称的联系人,但不添加电话号码或电子邮件。样本输入(用于传输的字符串,然后在发送到函数之前解析)...
{"name":"Test User",
"email":"test@website.com",
"phone":{
"0":{"type":"cell","number":"1231231234","pref":true},
"1":{"type":"home","number":"1231231235","pref":false}}}
有人知道为什么不添加电话号码/电子邮件吗?
编辑:结果对象没有长度...只有数组。电子邮件仍然无法正常工作。
答案 0 :(得分:1)
我认为contact.email
实际应该是contact.emails
,它也应该是contact.phoneNumbers
之类的数组。
这是确切的结构:
{"type":"home","value":"xxxx@yyyy.zz","id":0,"pref":false}