本节知识点
- 获取通讯录 plus.contacts.getAddressBook
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<style>
</style>
</head>
<body>
<header class="mui-bar mui-bar-nav">
<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
<h1 class="mui-title">联系人</h1>
</header>
<div class="mui-content">
<ul class="mui-table-view" id="listArea">
<li class="mui-table-view-cell" id="mode">
#
</li>
</ul>
</div>
<link href="css/mui.min.css" rel="stylesheet" />
<script src="js/mui.min.js"></script>
<script type="text/javascript">
mui.init();
mui.plusReady(function() {
// 扩展API加载完毕,现在可以正常调用扩展API
plus.contacts.getAddressBook(plus.contacts.ADDRESSBOOK_PHONE, function(addressbook) {
addressbook.find(["displayName", "phoneNumbers"], function(contacts) {
for(var i = 0, len = contacts.length; i < len; i++) {
var li = document.getElementById("mode").cloneNode(true);
li.innerHTML = contacts[i].displayName + "<br/>手机:" + (contacts[i].phoneNumbers.length == 0 ? "" : contacts[i].phoneNumbers[0].value);
document.getElementById("listArea").appendChild(li);
}
}, function() {
mui.toast("获取电话簿失败 ");
}, {
multiple: true
});
}, function(e) {
mui.toast("获取电话簿失败 " + e.message);
});
});
</script>
</body>
</html>