在钛我访问电话簿时,我有一个包含联系信息的数组(单值和多值字段)。我在多值电子邮件领域遇到麻烦。多值字段字符串化对象看起来像这样(工作,家庭,其他以及工作,家庭等多个电子邮件):
email: {"work":["kate-bell@mac.com","www.icloud.com"]}
phone: {"work":["(555) 766-4823"],"other":["(707) 555-1854"]}
我到目前为止的代码:
function buddy_check(){
var all_emails= []; // array of emails from senders contacts
var multiValue = ['email'];
var people = Ti.Contacts.getAllPeople(); // gets all contacts (recordId, name,…)
for (var i=0, ilen=people.length; i<ilen; i++){
Ti.API.info('---------------------');
var person = people[i];
//for (var j=0, jlen=singleValue.length; j<jlen; j++){
// Ti.API.info(singleValue[j] + ': ' + person[singleValue[j]]);
// }
for (var j=0, jlen=multiValue.length; j<jlen; j++){
Ti.API.info(multiValue[j] + ': ' + JSON.stringify(person[multiValue[j]]));
all_emails.push();
}
}
我需要将电话簿的所有电子邮件放在一个数组中,用逗号分隔。下划线功能也可以。
我必须推送到all_emails数组?是否有更简单的方法来提取电子邮件并将其放入数组中(例如搜索“@”)?
分享见解!
P.S:用户当然被告知正在使用我们的数据库检查电子邮件。
答案 0 :(得分:0)
var data = [];
var people = Ti.Contacts.getAllPeople();
for (var i = 0,
ilen = people.length; i < ilen; i++) {
var person = people[i];
var title = people[i].fullName;
if (!title || title.length === 0) {
title = "No Name";
}
Ti.API.info("person name : " + title);
var personEmails = [];
//this check is used for conforming that array will contain at least one email that is actual.
var actualConfirmed = false;
//fetching emails
//Ti.API.info("person email::::1 " + JSON.stringify(person.email));
for (var temp in person.email) {
var temp_emails = person.email[temp];
if (temp_emails && (temp_emails.length > 0)) {
//Ti.API.info("person email::::2 " + JSON.stringify(temp_emails));
for (var k = 0; k < temp_emails.length; k++) {
var temp_email = temp_emails[k];
var isActualEmail = emailValidation(temp_email);
Ti.API.info("temp_email " + temp_email + " :::: isActualEmail " + isActualEmail);
if (isActualEmail) {
actualConfirmed = true;
personEmails.push(temp_email);
}
}
}
}