【发布时间】:2014-02-11 04:30:58
【问题描述】:
我有以下代码,我成功地使用它来生成手机上所有联系人的列表或所有联系人的搜索结果。我让它与姓名和电话号码一起使用,其中一个联系人的多个记录显示为多个列表条目,这正是我想要的方式。我遇到的问题,也许我在这里遗漏了一些明显的东西,是我无法让任何其他字段显示在列表中。我尝试使用下一个字段向 j 变量添加“或”,虽然它返回相同的结果,但只要我将下一个字段添加到列表中,它就会全部中断。我确实一直得到结果,但我无法显示结果。我还试图找出一种添加另一个“for”循环的方法,但正如预期的那样,他们总是过滤掉已经过滤的结果,通常只给我一个结果。 js如下,任何帮助表示赞赏。我真的不能像它的科尔多瓦那样做小提琴。
// search below
var fields = ["givenName", "familyName", "name", "emails", "phoneNumbers", "addresses", "organizations"],
options = new ContactFindOptions();
var filter = $('#contacts_filter')[0].value
// set Options
options.filter = (filter && filter !== "Search All") ? filter : "";
options.limit = 15; //doesn't work for some reason
options.multiple = true;
//find function
navigator.contacts.find(fields, function (foundContacts) {
//if their are results
if (foundContacts.length > 0) {
$("#contact_list").html("<h5 style='text-align: center'>" + foundContacts.length + " results found.</h5>");
for (var i = 0; i < foundContacts.length; i++) {
if(null != foundContacts[i].phoneNumbers )
{
for(var j=0; j < (foundContacts[i].phoneNumbers.length); j++)
{
$('#contact_list').append("<li><h2>" + foundContacts[i].name.familyName + ", " + foundContacts[i].name.givenName + "</h2><p>" + foundContacts[i].addresses[j].streetAddress + "</p><p>" + foundContacts[i].phoneNumbers[j].value + "</p></li>");
}
}
}
} else {
$("#contact_list").html("<h5 style='text-align: center'>No Contacts Found!</h5>");
}
编辑:移除了无关的 id。
【问题讨论】:
标签: javascript ios cordova contacts phonegap-plugins