- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在创建一个phonegap应用程序来获取联系人并将其保存在数据库中。我在顶部创建了两个空的全局数组,用于保存人员的电话号码和显示名称,稍后将其存储在数据库表中。为了检查联系人是否已成功保存在数组中,我创建了一个 test_data()
函数。
现在我的问题是 test_data()
代码不起作用,日志中没有显示任何值。现在,如果我将该代码从 test_data()
函数移动到 onSuccess()
,它就可以正常工作。这是代码。这不是在JS中声明全局数组的正确方法吗?
<!DOCTYPE html>
<html>
<head>
<title>Contact Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-1.7.0.js"></script>
<script type="text/javascript" charset="utf-8">
var gcont = []; var gphon = [];
// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
// find all contacts with 'Bob' in any name field
var options = new ContactFindOptions();
options.filter="";
options.multiple=true;
var fields = ["displayName", "phoneNumbers"];
navigator.contacts.find(fields, onSuccess, onError, options);
test_data();
}
// onSuccess: Get a snapshot of the current contacts
//
function onSuccess(contacts) {
for(var index=0;index<contacts.length;index++){
gcont[index] = contacts[index].displayName;
gphon[index] = contacts[index].phoneNumbers[0].value;
}
}
function test_data(){
for (z=0;z<gcont.length;z++){
console.log(gcont[z]);}
}
// onError: Failed to get the contacts
//
function onError(contactError) {
alert('Error With Contacts!');
}
</script>
</head>
<body>
<h1>Example</h1>
<p>Find Contacts</p>
</body>
</html>
最佳答案
对 test_data() 的调用在 onDeviceReady() 中不起作用,因为对 contact.find 的 onSuccess 回调是异步的,并且执行 test_data() 时尚未填充数组。
关于使用 Phonegap 全局数组的 Javascript 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10469843/
Example image 如何在 Phonegap 中添加像这张图片这样的 float 气泡通知。 最佳答案 没有您正在寻找的“开箱即用”插件。但是,您可以创建自己的插件或简单地使用 phonega
我正在使用 HTML 和 JS、JQuery Mobile 构建一个应用程序,并使用 PhoneGap Build 进行打包。客户想知道是否可以添加打印功能...有人知道吗?没有 PG Build 打
我已经安装了 Phonegap 使用 $ npm install -g PhoneGap 我也创建了项目。之后我做了 $ PhoneGap build android 它给出了 [phonegap]
我尝试创建 Phonegap 项目,其中需要集成 ASIHTTPRequest 和 JASON 引用, 并出现以下错误 ld: duplicate symbol _SBJSONErrorDomain
我有一个 Phonegap 应用程序,我从早期版本的 Phonegap 开始,我想升级到最新版本。我需要采取哪些步骤来升级它? 我正在寻求一般性答案,但我的具体情况是 Phonegap 1.1.0 -
我已在我的 MAC 电脑(IOS 10.5.8,SDK 3.1.2)上成功安装 PhoneGap。尝试创建一个新的基于 PhoneGap 的应用程序,包含 PhoneGap 框架并将所需的文件复制到
我正在 phonegap 中为三个不同的平台构建一个应用程序:Android、iOS 和 Blackberry。这样做时,我必须检测设备类型,以便我可以在不同平台和不同设备(如 Android Pho
开始在Mac上使用phonegap(Xcode 4,构建iPhone应用程序)我已经阅读了很多有关名为phonegap.plist的文件的内容,包括外部URL的白名单和其他内容。 这是我的问题,我在
所以我有一个运行 Phonegap 1.4.0 的应用程序(不要问),我决定升级到 1.8.1,这样做时 Phonegap 全局变量不再存在,将被替换为实用程序。 所以我转换了每一次出现: var t
我尝试了什么: 我正在开发一个安卓应用程序。在我的应用程序中,我必须打开 -> 向用户显示 Microsoft Office 文档(doc、docx、xls、xlsx、ppt、pptx)内容。为此,我
使用phonegap制作iOS应用时,ChildBrowser插件可以打开一个可以使用phonegap功能的远程页面吗? 例如:在phonegap应用程序中的index.html,调用childbro
我有一个带有 angularjs 的网络应用程序。我想使用 phonegap 将它变成一个移动应用程序 (android)。 我使用了 phonegap 构建:https://build.phoneg
我正在使用 Phonegap build 为每个平台生成可执行文件。每次更改代码时,我都必须在 phonegap build 上上传代码并生成新的 Apk 文件(适用于 android)。我不想在真实
我很生气,这是毫无疑问的,除了明显的可见差异之外,有人报告高度为: $('body').outerHeight(); //1780 与在我的本地 Windows 8 机器上使用 phonegap
我最近使用 phonegap 完成了我的第一个混合应用程序项目。当谈到公开测试时,我有点害怕签名过程。我从这里以及网上的其他地方阅读了许多不同的建议 fragment 来完成这项工作。 以下是如何为
我是 phonegap 的新手,我尝试创建一个简单的 phonegap 应用程序。 使用命令行安装phonegap后:--- 我已经成功创建了项目,但是当我尝试运行 phonegap build io
我正在为 Android 平台制作一个 phonegap 应用程序。在这个应用程序中,我想在多个 html 页面中滑动导航。请告诉我该怎么做。要么在单个 html 页面中完成,要么我必须为此滑动导航创
是否有任何插件可用于 Juce我可以添加哪些库可以同时适用于 IOS 和 android?如果没有,我如何集成 Juce我的电话间隙应用程序中的库? 最佳答案 没有插件。但您可以使用介绍榨汁机来创建不
Phonegap 刚刚推出了一种方法,可以使用以下命令使用本地服务器立即查看您对 phonegap 应用程序的更改: phonegap serve 然后通过下载 PhoneGap Developer
我们对如何集成phonegap插件,然后使用phonegap build构建我们的移动应用程序有一些疑问,这可能吗? 当您使用 Phonegapbuild 构建您的应用程序时,它会为所有受支持的设备构
我是一名优秀的程序员,十分优秀!