0

我有一个工作的网络桌面应用程序,与开箱即用的 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
},

...

});

4

2 回答 2

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 个模块窗口,并将它们并排放置在桌面上。

于 2011-12-12T18:09:48.593 回答
0

您在这里遇到了范围界定问题。尝试将 init 方法更改为 initComponent。

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

于 2011-12-10T00:31:39.510 回答