Contacts of Firefox OS problems with mozContacts.tel



我一直在尝试获取联系人名称和姓氏,还可以获取手机号码,但是当我使用getAll()方法时,控制台显示此信息:

Found: Daniel Garcia [object Object]

您可以看到它显示Name LastName tel。为什么它显示tel,例如[object Object]

这是我的代码:

var allContacts = navigator.mozContacts.getAll({
    sortBy: "givenName",
    sortOrder: "ascending"
});  
allContacts.onsuccess = function(event) { 
    if (cursor.result) { 
        if (cursor.result.familyName[0]== undefined) {
            cursor.result.familyName[0]= ""; 
        }  
        console.log("Found: " + cursor.result.givenName[0] + " " + cursor.result.familyName[0] + ' ' + cursor.result.tel[0]); 
        cursor.continue();
    } else {
        console.log("No more contacts");
    }
}

tel这是一个对象数组 - 联系人的所有可能电话号码的列表。每个对象都有几个有用的属性。在JavaScript中打印一个对象时,它会打印对象字符串表示(例如[object Object])。

查看文档以了解tel对象的结构并按照您想要的方式进行打印:https://developer.mozilla.org/en-us/docs/web/api/mozcontact.tel.tel

非常感谢您像Aras和Jamesh一样

console.log("Found: " + cursor.result.givenName[0] + " " + cursor.result.familyName[0]+' '+JSON.stringify(cursor.result.tel[0]));    

和控制台显示以下内容:

"Found: Daniel Garcia {"type":["mobile"],"value":"8112441018"}"

最新更新