本文介绍了未捕获的Ref​​erenceError:ContactFindOptions没有定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有科尔多瓦/ PhoneGap的联系人时出现问题。结果
这是code我试图来执行,我把外部JavaScript文件:

I have a problem with cordova/phonegap contacts.
This is the code i am trying to execute, i put in an external javascript file:

function onDeviceReady() {
// find all contacts
var options = new ContactFindOptions();
options.filter = "*";
var fields = ["displayName", "name"];
navigator.contacts.find(fields, onSuccess, onError, options);
}

// onSuccess: Get a snapshot of the current contacts

function onSuccess(contacts) {
for (var i = 0; i < contacts.length; i++) {
    console.log("Display Name = " + contacts[i].displayName);
}
}

// onError: Failed to get the contacts

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

这是从PhoneGap的API文档的code:

This is the code from the phonegap API documentation:link

原来的code是要找到在各个领域鲍勃的所有联系人。结果
我把它改为*(只是一星)我所有的联系人。

The original code is to find all contacts with 'bob' in every field.
I changed it to "*"(Just a star) for all my contacts.

功能onDeviceReady只是通过点击一个按钮调用。

The function onDeviceReady is just called by a button click.

我在logcat中得到的错误是这样的:

The error I get in the logcat is this:

[INFO:CONSOLE(81)] "Uncaught ReferenceError: ContactFindOptions is not defined"
81 is the linenumber with: var options = new ContactFindOptions();

有谁知道怎样做才能获得的功能ContactFindOptions()工作的?

Does anyone know what to do to get the function ContactFindOptions() work?

如果您需要更多的信息,只是让我知道。

If you need more info, just let me know.

推荐答案

使用PhoneGap的Andr​​oid上访问联系人: -

Access contacts on Android using Phonegap:-

function onDeviceReady() {
    // specify contact search criteria
    var options = new ContactFindOptions();
    options.filter="";          // empty search string returns all contacts
    options.multiple=true;      // return multiple results
    filter = ["displayName"];   // return contact.displayName field

    // find contacts
    navigator.contacts.find(filter, onSuccess, onError, options);
}

var names = [];

// onSuccess: Get a snapshot of the current contacts
//
function onSuccess(contacts) {
    for (var i=0; i<contacts.length; i++) {
        if (contacts[i].displayName) {  // many contacts don't have displayName
            names.push(contacts[i].displayName);
        }
    }
    alert('contacts loaded');
}

您可以尝试读取如何使用我提供了一些链接,这将有助于你的和创建与PhoneGap的一个充分接触的例子

you can try to read the documentation and implementation of how to use I'm providing some link which will help you Saving Contacts with PhoneGap Android and Example of Creating a full contact with PhoneGap

这篇关于未捕获的Ref​​erenceError:ContactFindOptions没有定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 18:29
查看更多