简体   繁体   English

加载谷歌图表API时,PhoneGap(Cordova)应用程序崩溃

[英]PhoneGap (Cordova) app crashes when loading google chart API

I'm testing this app on a iOS Simulator 我正在iOS模拟器上测试这个应用程序

Whenever I run this code: 每当我运行此代码时:

google.load("visualization", "1", {packages:["corechart"]});

My phonegap application crashes to a completely white screen. 我的phonegap应用程序崩溃到一个完全白色的屏幕。 I have a page, where I have some random content and a button, that is assigned a .click() jQuery listener to start loading the google chart api. 我有一个页面,我有一些随机内容和一个按钮,分配一个.click() jQuery监听器,开始加载谷歌图表API。 Whenever I click that button, everything dissapears and I'm left with a blank screen. 每当我点击那个按钮,一切都消失了,我留下了一个空白的屏幕。

Here's the code: 这是代码:

$( '#chartsThirdStep' ).live( 'pageinit',function(event){

    $("#chartThirdStepGoButton").click(function(event){

        parseChartInfo();
    });
});

function parseChartInfo() {

    console.log("parseChartInfo()");
    google.load("visualization", "1", {packages:["corechart"]});
    // app completely crashes here - all jquery mobile stuff dissapears
    // and i'm left with a blank screen on the simulator.
    //google.setOnLoadCallback(drawChart);
}

I'm using: 我正在使用:

first, you need to load the API outside the "ready" event handler, as the loader doesn't seem to work properly inside other functions. 首先,您需要在“ready”事件处理程序之外加载API,因为加载程序似乎在其他函数中不能正常工作。
Second, put the click event handler inside the google.load callback, which will prevent the click event from being assigned before the API loads (and thus users can't try to draw charts before the API loads, though it typically loads sufficiently fast that your users should never notice a difference) 其次,将click事件处理程序放在google.load回调中,这将阻止在API加载之前分配click事件(因此用户无法在API加载之前尝试绘制图表,尽管它通常加载足够快,你的用户永远不会注意到差异)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM