ExtJS 4 MVC桌面 - 如何以编程方式创建/打开模块

时间:2011-12-09 20:25:51

标签: extjs4 extjs-mvc

我有一个工作的网络桌面应用程序非常类似于开箱即用的ExtJS桌面示例,其中有许多图标,点击后会产生一个窗口。

我试图弄清楚如何以编程方式执行相同的操作:

var x = Ext.create('MyApp.view.users.Module')
x.launcher.handler();

这会调用createWindow()函数,第一行是:

var b = this.app.getDesktop();

这条线炸弹:

无法调用未定义的方法'getDesktop'

这显然意味着“this”上没有“app”。

我是ExtJS新手,不知道如何将模块绑定到应用程序,或者如何在点击图标的方式正确抓取模块。任何帮助将不胜感激。

模块代码:

Ext.define('MyApp.view.users.Module', {

requires:                     ["Ext.tab.Panel"],
alias:                        'widget.usersmodule',
extend:                       'Ext.ux.desktop.Module',
id:                           'users-module-win',
itemId:                       'usersmodule',

init:                          function(){
    this.launcher = {
        handler:               this.createWindow,
        iconCls:              'icon-users',
        scope:                 this,
        text:                 'Users',
        windowId:             'users-module-win'
    }
},

...

createWindow:                    function(){
    var b = this.app.getDesktop();
    var a = b.getWindow('users-module-win');

    ...

    a.show();
    return a
},

...

});

2 个答案:

答案 0 :(得分:3)

好的,我找到了解决此问题的方法之一。

当我在创建应用程序时创建桌面应用程序时,我将全局变量设置为该操作的结果:

var _myDesktopApp;

Ext.application({

appFolder:'MyApp',

controllers:[
  ....
],

name:'MyApp',

launch:function () {

        Ext.Loader.setPath({
            ....
        });

        Ext.require('MyDesktop.App');
        Ext.require('Ext.tab.*');

        Ext.onReady(function () {
            _myDesktopApp = Ext.create('MyDesktop.App');
        });
    };
}

});

然后在我的桌面文件中,我可以获得一个特定的模块并使用一些初始大小设置打开它:

Ext.define("MyDesktop.App", {
extend:                     "Ext.ux.desktop.App",
requires:                    [
    "Ext.window.MessageBox",
    "Ext.ux.desktop.ShortcutModel",

    "MyApp.view.prospects.Module",        
    "MyApp.view.users.Module"
],
init:                        function () {
    this.callParent();

    var prospects_width = 700;
    var prospects_height = 500;
    var prospects_x = 0;
    var prospects_y = 0;
    _myDesktopApp.getModule('prospects-module-window').createWindow(prospects_width, prospects_height, prospects_x, prospects_y);

    var users_width = 700;
    var users_height = 500;
    var users_x = 700;
    var users_y = 0;
    _myDesktopApp.getModule('users-module-window').createWindow(users_width, users_height, users_x, users_y);
},

....

此代码在加载时打开2个模块窗口,并将它们并排放置在桌面上。

答案 1 :(得分:0)

你有一个范围问题在这里发生。尝试将init方法更改为initComponent。

使用带Firebug的Firefox调试您的应用。在var b = ... line上放置断点并查看范围内的变量。

相关问题