Aje*_*sad 2 javascript phonegap-plugins cordova
我正在使用Phonegap示例应用程序列出所有名称的联系人,但我无法这样做.
以下是我的onSuccess()
功能.我在这个函数的第二行中找到了7个联系人作为消息.我在获得这个名字的试验中展示了一些结果.
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);
}
};
Run Code Online (Sandbox Code Playgroud)
试验:
<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.
Run Code Online (Sandbox Code Playgroud)
我怎样才能获得名称字段?
好吧,我还没有测试过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 }
);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5030 次 |
最近记录: |