我正在创建Cordova Phonegap应用程序。使用以下代码,我可以获取保存在PhoneBook中的所有联系人。但我想只获取保存在我的数据库中的那些联系人。在这里,我也使用jQuery Mobile。
<!DOCTYPE html>
<html>
<head>
<title>Contact Example</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css"/>
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady()
{
var options = new ContactFindOptions(); // specify contact search criteria
options.filter=""; // empty search string returns all contacts
options.multiple=true; // return multiple results
filter = ["displayName", "phoneNumbers"];
navigator.contacts.find(filter, onSuccess, onError, options); // find contacts
}
//onSuccess: Get a snapshot of the current contacts
function onSuccess(contacts)
{
$("#userList").html('');
for (var i=0; i<contacts.length; i++)
{
var htmlData="<li><a href='#' data-role='button' id='btn"+i+"' data-id='"+i+"' data-con='"+contacts[i].displayName+"' data-flag='"+contacts[i].phoneNumbers[0].value+"' onclick='giveme_result(this);'>" +contacts[i].displayName+ "<p class='ui-li-aside'>" + contacts[i].phoneNumbers[0].value+ "</p></a></li><br/>";
$("#userList").append(htmlData).listview('refresh');
}
};
function giveme_result(ref)
{
var i = $(ref).attr("data-id");
var con_name = $(ref).attr("data-con");
var flag = $(ref).attr("data-flag");
if( flag != null)
{
$.mobile.changePage ($("#page2"), { transition : "none", reverse : false });
document.getElementById("num_content").innerHTML = "Mobile Number : " + flag + "<br/>";
document.getElementById("con_name").innerHTML = "Name : " + con_name + "<br/>";
$("#profile_btn").live("click" , function(){
$.mobile.changePage($("#page3"), {transition : "none", reverse : true })
})
}
}
function onError(contactError)
{
alert('onError!');
}
</script>
</head>
<body>
<div data-role = "page" id = "index">
<div data-role="content">
<ul data-role="listview" data-filter="true" data-filter-placeholder="Search..." id="userList"> </ul>
</div>
</div>
<!------------ index_end------------------->
<div data-role = "page" id = "page2">
<div data-role="content" id = "num_content"></div>
<div data-role="content" id = "con_name"></div>
</div>
</body>
</html>
PS:在PHP中创建用于数据库交互的Web服务。我还添加了联系人和文件传输插件。 有人可以尽快帮忙吗?
提前致谢。