【问题标题】:push multivalue elements to array in titanium (JS)将多值元素推送到钛(JS)中的数组
【发布时间】:2014-12-11 10:12:34
【问题描述】:

在钛中,我正在访问电话簿,我有一个包含联系信息的数组(单值和多值字段)。我在使用多值电子邮件字段时遇到问题。多值字段字符串化对象如下所示(工作、家庭、其他以及多个工作电子邮件、家庭等):

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:用户当然会被告知正在使用我们的数据库检查电子邮件。

【问题讨论】:

    标签: javascript arrays titanium field multivalue


    【解决方案1】:

    从这里:http://www.oodlestechnologies.com/blogs/How-to-extract-contact-list-having-phone-numbers-and-emails-from-iPhone-contacts-using-Titanium

    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);
                    }
                }
            }
        }
    

    - 查看更多信息:http://www.oodlestechnologies.com/blogs/How-to-extract-contact-list-having-phone-numbers-and-emails-from-iPhone-contacts-using-Titanium#sthash.q7TJF8Lg.dpuf

    【讨论】:

      猜你喜欢
      • 2013-01-21
      • 1970-01-01
      • 1970-01-01
      • 2022-01-23
      • 2018-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多