gpt4 book ai didi

javascript - 使用 Phonegap 显示联系人列表

转载 作者:行者123 更新时间:2023-11-29 16:15:09 25 4
gpt4 key购买 nike

我正在使用 Phonegap 示例应用程序列出所有联系人及其姓名,但我无法这样做。

下面是我的 onSuccess() 函数。我在这个函数的第二行收到了一条消息 Found 7 contacts。我正在展示我尝试获取名称的一些结果。

function onSuccess(contacts) {
navigator.notification.alert('Found ' + contacts.length + ' contacts.');
var con = document.getElementById('con');

for (var i = 0; i < contacts.length; i++) {
navigator.notification.alert(contacts[i].name);
}
};

试验:

  <br/>
1). navigator.notification.alert(contacts[i])<br/>
Result ->
{"id":"0","displayName":"Andrew Hill","nickname":"Andrew Hill",
"phoneNumbers":["(206)5550001"],"emails":["Andy@fai=urthcoffee.com"],
"addresses":["Microsoft.Phone.UserData.ContactAddress"],
"urls":["www.fourthcoffee..com"]}
and like in the same foramt for other 6 contacts.

2). navigator.notification.alert(contacts[i].name)<br/>
Result ->
message
like same for all.

3). navigator.notification.alert(contacts[i].name[i].value)<br/>
Result ->
shows nothing.

如何获取名称字段?

最佳答案

好吧,我还没有针对 Windows Phone 7 进行测试,但它在 iOS/android 上运行良好,在设备和模拟器上都进行了测试。

navigator.contacts.find(
['displayName', 'name','phoneNumbers'],
function(contacts){
var contact_name;
var contact_phone;
for( i = 0; i < contacts.length; i++) {
if(contacts[i].name.formatted != null && contacts[i].name.formatted != undefined ) {
contact_name = contacts[i].name.formatted;
contact_name = contact_name.replace(/'/g,"''");
if(contacts[i].phoneNumbers != null && contacts[i].phoneNumbers.length > 0 && contacts[i].phoneNumbers[0].value != null && contacts[i].phoneNumbers[0].value != undefined ) {
console.log( contacts[i].phoneNumbers[0].value );
contact_phone = contacts[i].phoneNumbers[0].value;
} else {
console.log( "--No Number-" );
contact_phone = "";
}
}
}
},function(error){
alert(error);
},{ filter:"", multiple:true }
);

关于javascript - 使用 Phonegap 显示联系人列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17647744/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com