0

我的任务是将Phonegap + Sencha 项目从Phonegap 1.2.0 升级到2.1.0 和Sencha 2,我一直在Chrome+jetty 下直接进行调试,修改之间的迭代速度更快。

在迁移部分苦苦挣扎之后,我到达了项目在 Chrome 上启动的地步(即:我可以在调试器上执行我的启动方法,并加载应用程序),但是当我在 Android 上尝试同样的事情时,我得到了Uncaught ReferenceError: app is not defined

在 android 中调用的 HTML 文件如下所示:

<html>
<head>
    <title>Testing ExtJS 4</title>
        <link rel="stylesheet" href="libs/sencha/resources/css/android_v01.css" type="text/css">
        <link rel="stylesheet" href="libs/hx/resources/css/prosegur.css" type="text/css">

        <!-- libs -->
        <script type="text/javascript" charset="utf-8" src="libs/phonegap/cordova-2.1.0.js"></script>
        <script type="text/javascript" src="libs/sencha/sencha-touch-all-compat.js"></script> 
        <script type="text/javascript" src="libs/jquery/jquery-1.7.1.min.js"></script>
        <script type="text/javascript" src="libs/jquery/xml2json.js"></script>
        <script type="text/javascript" src="libs/aes/aes.js"></script>
        <script type="text/javascript">
            currentPlatform="Android";
        </script>
        <script type="text/javascript" src="app/App.js"></script>

        <script type="text/javascript">

db_name="PMobileDB";
db_version="1.0";
DEBUG_MODE=false;
LOG_FILE="sdcard/xlogx.txt";

function fireCreateLocalStore() {   
 var prosegurConfig = window.localStorage.getItem('ProsegurConfig');
 if (prosegurConfig == null) {
    prosegurConfig = new Object();
    prosegurConfig.configuration = {
        esClienteProsegur: false,
        estaActivadoClienteProsegur: false,
        nroContrato: '',
        paisDeContrato: 'ARG',
        paisDeResidencia: 'ARG',
        nombre: '',
        cel: '',
        fechaNacimiento: '',
        email: '',
        estado: 'NO_CONFIGURADO',
        wsMobileConfig: 'https://psm.am:1962/wsProseguardConfig.asmx/wsMobileConfig',
        wsHashActivation: 'https://psm.am:1962/wsProseguardConfig.asmx/wsHashActivation',
        wsAlertFire: 'https://psm.am:1962/wsProseguardAlerts.asmx/wsAlertFire',
        guardianPin: '',
        startGuardianAlertTime: '',
        version: db_version
    };
    prosegurConfig.alerts = [
        { 
            alertType: 'GENERAL',
            description: '', 
            tryContactCRA: false
        },
        {
            alertType: 'MEDICAL',
            description: '',
            tryContactCRA: false
        },
        {
            alertType: 'CARASSISTANCE',
            description: '',
            tryContactCRA: false
        }
    ];
    prosegurConfig.contacts = new Array();
    window.localStorage.setItem('ProsegurConfig', Ext.JSON.encode(prosegurConfig));
    console.log('se carga los datos iniciales de Prosegur');
 }
 console.log(prosegurConfig);
 console.log('arranco app.mainLaunch()');
 app.app.launch();
 console.log('salgo de app.mainLaunch');
}
</script>
<script type="text/javascript">document.addEventListener("deviceready", fireCreateLocalStore,false);
</script>
</head>
<body></body>
</html>

首先,我知道app对于全局对象来说是一个糟糕的选择,我认为特定的东西在 1.4.0 和 1.5.0 之间发生了变化,所以,虽然对 launch() 方法的原始调用是这样的:

app.launch();

我发现这在 2.1.0 中不起作用,我可以这样称呼它:

app.app.launch();

这在 Chrome 中可以正常工作,从我上面粘贴的代码中调用 fireCreateLocalStore() 结束调用它。

现在,当我在 Eclipse 中编译它并使用调试选项部署它时,我看到 logcat 正在创建数据库对象(就在之前),当它到达 launch() 行时,我从标题中得到错误:未捕获ReferenceError:应用程序未定义

我尝试将有问题的全局更改为不那么冲突的东西,例如 html 中的 MyApp 和 App.js(加上默认视图)无济于事,因此现在,我有点坚持这一点。

顺便说一句,我的 App.js 看起来像这样:

// Main application entry point
Ext.application({
name: 'app',
phoneStartupScreen: '../resources/images/LOADING_01.png',
tabletStartupScreen: '../resources/images/LOADING_01.png',
glossOnIcon: true,
    fullscreen: true,
autoCreateViewport : true,

// the controller will take care of creating the view        
//controllers: ['Configuration', 'ImmediateAlert', 'Guardian', 'Log'],
controllers: ['Configuration', 'ImmediateAlert', 'Guardian'],

// You could delete this, here only to illustrate
   // the sequence of events        
initialize: function () {
    console.log('app initialize');
    this.callParent();
},

launch: function() {
    console.log(app);
    this.launched = true;
    Ext.create("app.view.Viewport");
    this.mainLaunch();
},
mainLaunch: function() {
    //if (!device || !this.launched) {return;}
    if (!this.launched) {return;}
    console.log('MainLaunch : loading in ' + currentPlatform );

    Ext.getCmp('navigationView').getNavigationBar().add({id: 'save',
        text: 'Guardar',
        ui: 'light',
        align: 'right',
   })

   if (app.store == undefined)
        app.store = new Object();

   app.store.contacts = Ext.create('Ext.data.Store', {
       model: "app.model.Contact"
   });

   app.store.alerts = Ext.create('Ext.data.Store', {
        model: 'app.model.Alert',
   });

   app.service.ProsegurLocalStorageStore.populateStores(app.store.alerts);

   app.service.ProsegurLocalStorageStore.populateContactStores(app.store.contacts);

   var config = app.service.ProsegurLocalStorageStore.getConfiguration();
            console.log('ATENCION' + app.configuration.GeneralConfiguration.fireAlertService());
   if (config.data.wsBaseURL != null && config.data.wsBaseURL != '') {
        app.configuration.GeneralConfiguration.prosegurServiceBaseURL = config.data.wsBaseURL;
    }
    if (config.data.wsBaseCriticalURL != null && config.data.wsBaseCriticalURL != '') {
        app.configuration.GeneralConfiguration.prosegurServiceCriticalBaseURL = config.data.wsBaseCriticalURL;
    }

   if (currentPlatform == "MacOS"){ 
       navigator.geolocation.getCurrentPosition();
    }


   Ext.MessageBox.YESNO=[{itemId:'no',text:'NO'},{itemId:'yes',text:'Si'}];
   Ext.MessageBox.OK = {itemId:'ok',text:'Aceptar'};
   Ext.MessageBox.OKCANCEL=[{itemId:'cancel',text:'Cancelar'},{itemId:'ok',text:'Aceptar'}];



   Ext.Date.dayNames = [
                        'Domingo',
                        'Lunes',
                        'Martes',
                        'Miercoles',
                        'Jueves',
                        'Viernes',
                        'Sabado'
                    ];

                    Ext.Date.monthNames = [
                        'Enero',
                        'Febrero',
                        'Marzo',
                        'Abril',
                        'Mayo',
                        'Junio',
                        'Julio',
                        'Agosto',
                        'Septiembre',
                        'Octubre',
                        'Noviembre',
                        'Diciembre'
                    ];

                    Ext.Date.monthNumbers = {
                        'Ene': 0,
                        'Feb': 1,
                        'Mar': 2,
                        'Abr': 3,
                        'May': 4,
                        'Jun': 5,
                        'Jul': 6,
                        'Ago': 7,
                        'Sep': 8,
                        'Oct': 9,
                        'Nov': 10,
                        'Dic': 11
                    };

                    if (Ext.is.Android) {
                          Ext.EventManager.onWindowResize(function() {
                            Ext.Viewport.scrollToTop();
                            Ext.Viewport.updateBodySize();
                            Ext.Viewport.fireEvent('resize', Ext.Viewport, Ext.getBody().getSize());
                            app.views.viewport.getActiveItem().fireEvent('resize');
                          });
                    };

                    app.service.ProsegurServiceCallbackDaemon.run();
}
});
4

1 回答 1

0

“app”很可能与“navigator.app”冲突,后者是一个PhoneGap API。如果您可以更改 Sencha 应用程序的名称,那可能是您最好的选择。

于 2012-10-26T13:39:36.113 回答