当前位置: 动力学知识库 > 问答 > 编程问答 >

android - Sencha Touch 2: How to initialize controller of a package?

问题描述:

I have a ST2.3 app in a workspace, which use a package composed of a controller and two views.

I can access the views without referencing them in app.js without a problem, but I can't access the controller and the events fired by the views of the package aren't catched by the controller.

I already tried to reference the controller by doing the following in app.js:

controllers: [

'packageController', OR

'[email protected]', OR

'package.controller.packageController'

...

]

None works and throws a "file not found" error.

Workspace architecture:

workspace/

touch/

...

STApp/

...

packages/

package1/

src/

view/

...

controller/

packageController.js

Note: The app is packaged for native android device with Cordova.

Any ideas ?

***EDIT:

I found this in the sencha.cfg of the package, maybe it is related and I have to somehow specify the controller folder ? :

# This is the comma-separated list of folders where classes reside. These

# classes must be explicitly required to be included in the build.

#

package.classpath=${package.dir}/src

网友答案:

So it could be one of a few things.

First, be sure you have configured the Ext.Loader in your app.js with the proper namespace/paths:

Ext.Loader.setConfig({
    enabled : true,
    paths   : {
        'Ext' : '../touch/src',

        //assuming "Foo" is the namespace
        'Foo' : '../packages/foo/src'
    }
});

Also be sure to add your package to the "requires" array in app.json.

requires : [
    'Foo' //name of the package from /packages/foo/package.json
]

Next, check the name of the actual class defined in packages/package1/src/controller/packageController.js. Sencha Cmd can be a bit finicky... the class name has to match the file name exactly -- and the fact you have "packageController" as the file name (in camelCase) throws a red flag for me.

So a real example might be packages/foo/src/controller/Bar.js in which you'd find Ext.define('Foo.controller.Bar', {}).


At that point, you should be able to use the following in app.js:

Ext.application({
    //...

    controllers : [
        '[email protected]', //OR...
        'Foo.controller.Bar'
    ]
});

Finally you must also run sencha app refresh with Sencha Cmd, which will regenerate your bootstrap files.

Running your app in debug mode after all of these steps, you should see the network request for packages/foo/src/controller/Bar.js and (hopefully) it loads into your app.

网友答案:

I had this very same issue when I was creating my first controller in st2. I just created it manually by making a new file and naming it properly thought it's the wrong way and most probably leads to situation you described.

Proper way is to use the sencha command to generate the controller.

Did you use it to create the controller? I think there are some hidden things in the framework and it won't recognize your controller. Sencha command modifies the bootstrap file (at least I think it does) when controller is created using sencha generate controller <your controller name> and then you can tell in the app.js that you have a controller like this:

controllers:[
     '<MyControllerName>'
]

Run the above command in your projects root folder and it should work.

分享给朋友:
您可能感兴趣的文章:
随机阅读: