【发布时间】:2023-03-03 14:31:01
【问题描述】:
我正在使用构建在 Phonegap 之上的 dhtml 和 steroids.js 构建一个跨平台手机应用程序。我正在尝试使用 Cordova Contact API 将我手机中的联系人加载到 ul 元素中。这是我在头部标签中的代码。当我在我的 Android 设备上加载我的应用程序而不是在 iphone4 或 5 上时,它工作正常。
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
// find all contacts
var options = new ContactFindOptions();
options.filter="";
options.multiple=true;
var filter = ["*"];
navigator.contacts.find(filter, onSuccess, onError, options);
}
// onSuccess: Get a snapshot of the current contacts
//
function onSuccess(contacts) {
for (var i=0; i<contacts.length; i++) {
//alert(contacts[i].displayName);
var mycontact = contacts[i].displayName;
alert(mycontact);
//Just making sure if a contact is null, it won't be appended to the ul.
if(mycontact == null){
}
else
{
// Using a little jQuery to append to contacts to the ul
$("#contactlist").append('<li style="background-color:rgb (184,249,255);height:70px;overflow:hidden;border-top:solid 1px; border-bottom:solid 1px background-color:rgb(184,249,255);"><p style="font-family: Arial;font-size: 18px;top: 5px;position: relative;left: 10px;">' + mycontact + '</p></li>');
}
}
// ele.innerHTML = str;
}
// onError: Failed to get the contacts
//
function onError(contactError) {
alert('onError!');
}
</script>
【问题讨论】:
标签: javascript cordova