简体   繁体   中英

Adding a javascript variables file to Sencha Touch 2 android app

I've got an app I'm building in Sencha Touch 2 then packaging into android. What I want to include is a "defines.js" file which contains all my variables. (This app is to be altered for different people so this makes things easier to change)

I've got it to work fine on the browser by adding the script link to the index.html file, but when I package it up and run it on the android emulator it can't find the variables.

Any ideas? Ask if you need more information.

Currently the file resides under "resources/defines.js"

Edit:

I want to include a file containing variables for use in the app (titles etc)

It is called "defines.js".

I have linked it in the index.html using the following script tag:

<script type="text/javascript" src="resources/defines.js"></script>

I have also added into the to js section of the app.json:

"js": [
    {
        "path": "sdk/sencha-touch.js"
    },
    {
        "path": "app.js",
        "bundle": true,  /* Indicates that all class dependencies are concatenated into this file when build */
        "update": "delta"
    },
    {
        "path": "resources/defines.js"
    }
],

It works in a browser but not when I created a native android app.

You can try a more 'sencha' way.

First, remove the:

<script type="text/javascript" src="resources/defines.js"></script>

and also remove the entry on app.json:

{
    "path": "resources/defines.js"
}

Then, in your app.js add the resources path for the loader:

Ext.Loader.setPath({
    ....
    'Resources': 'resources'
});

Require the class:

Ext.application({
    ...
    requires: [
        'Resources.defines',
        ...
    ]
    ....
});

Define the class in the file resources/defines.js:

Ext.define('MyApp.resources.defines', {
    alternateClassName: 'Defines',
    singleton: true,

    BASEURL: 'localhost/myapp',
    APPVERSION: '0.1',

});

Tehn, you can access the object properties by:

Defines.BASEURL
Defines.APPVERSION

Hope it helps-

How are you creating packaging the android app? Using Sencha native packaging or the cordova packaging over Sencha touch

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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