【问题标题】:Cordova Contacts Plugin ContactFindOptions filterCordova 联系人插件 ContactFindOptions 过滤器
【发布时间】:2015-06-11 10:35:08
【问题描述】:

我在使用 cordova 的联系人插件时遇到了一些问题,我想为具有有效电话号码的联系人添加过滤器,如何添加正则表达式? javascript regex 似乎不起作用,我需要类似 [0-9]

function onDeviceReady() {
    // find all contacts with 'a phone number' in any name field
    var options = new ContactFindOptions();
    options.filter = '6'; // retriev all phones with a 6
    //options.filter = /[0-9]/ doesn't work
    var fields = ["phoneNumbers"];
    options.multiple = true;
    navigator.contacts.find(fields, onSuccess, onError, options);
}

// onSuccess: Get a snapshot of the current contacts

function onSuccess(contacts) {
    alert(contacts.length);
    alert(JSON.stringify(contacts));
}

// onError: Failed to get the contacts

function onError(contactError) {
    alert('onError!');
}

提前致谢!

【问题讨论】:

  • 我是否正确假设它是(注释掉的)行,options.filter = /[0-9]/,您没有开始工作,并且您想要关于如何仅过滤数字的建议?跨度>
  • 是的,注释行是行不通的。

标签: javascript regex cordova contacts


【解决方案1】:

我意识到他的最新更新现在包括一个仅获取具有电话号码的联系人的选项。选项 id 默认为 false。

options.hasPhoneNumber = true;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-02
    • 1970-01-01
    • 2014-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-28
    相关资源
    最近更新 更多