我想從聯繫人中獲取電話號碼的值,但我要麼將[object,Object]返回給我,要麼什麼也沒有。當我嘗試匹配[我] .phoneNumbers我得到[對象,對象],當我添加匹配[i] .phoneNumbers [0] .value,我的警報完全停止。.value返回Nothing(javaScript)
function callme() {
var options = new ContactFindOptions();
options.filter = ""; //leaving this empty will find return all contacts
options.multiple = true; //return multiple results
console.log(options);
var filter = ["displayName", "phoneNumbers"]; //an array of fields to compare against the options.filter
navigator.contacts.find(filter, successFunc, errFunc, options);
function successFunc(matches) {
for (var i = 0; i < matches.length; i++) {
//this loops through all of the contacts
var contact_name = matches[i].displayName;
var contact_number = matches[i].phoneNumbers; //this returns [object, Object]
// var contact_number = matches[i].phoneNumbers[0].value; returns nothing at all
var contact_full = contact_name + " " + contact_number;
}
alert(contact_full);
}
function errFunc() {
alert("oh no!");
}
};
[學習如何調試JavaScript](http://www.creativebloq.com/javascript/javascript-debugging-beginners-3122820)並使用'console.log'而不是'alert'。 –
爲什麼不用愚蠢的比賽[我]與console.log(匹配[我]),看看價值是否匹配的屬性 – alexmac
我不能使用console.log,因爲我正在測試這在手機上。 – MissElizabeth