简体   繁体   English

Ext JS 5 || 在窗口中创建应用程序

[英]Ext JS 5 || Creating an application in a window

Im currently creating an application that has as base start a window instead of a whole page. 我目前正在创建一个应用程序,该应用程序以启动窗口而不是整个页面为基础。 The main problem i'm running into is that for some reason i can't get my application to launch just like a normal application would. 我遇到的主要问题是由于某种原因,我无法像正常应用程序那样启动我的应用程序。 I've even tried creating a whole new project using the Sencha cmd to generate a clean application for me and replace the initial container that is used in the view with the default extjs window, but even then it wont work. 我什至尝试使用Sencha cmd创建一个全新项目,为我生成一个干净的应用程序,并将视图中使用的初始容器替换为默认的extjs窗口,但是即使这样,它也无法正常工作。 I was hoping that someone knows if this is even possible, and if so, how? 我希望有人知道这是否可能,如果可以,怎么办? Here is some code examples to show what i'm trying to do: 这是一些代码示例,以显示我要执行的操作:

App.js App.js

Ext.application({
    name: 'Extjs',

    extend: 'Extjs.Application',

    autoCreateViewport: 'Extjs.view.main.Main'

    //-------------------------------------------------------------------------
    // Most customizations should be made to Extjs.Application. If you need to
    // customize this file, doing so below this section reduces the likelihood
    // of merge conflicts when upgrading to new versions of Sencha Cmd.
    //-------------------------------------------------------------------------
});

app/Application.js app / Application.js

Ext.define('Extjs.Application', {
extend: 'Ext.app.Application',

name: 'Extjs',

stores: [
    // TODO: add global / shared stores here
],

launch: function () {
}});

app/view/Main.js app / view / Main.js

Ext.define('Extjs.view.main.Main', {
extend: 'Ext.window.Window',
requires: [
    'Extjs.view.main.MainController',
    'Extjs.view.main.MainModel'
],

xtype: 'app-main',

autoShow: true, //needs to be set for the window to show


controller: 'main',
viewModel: {
    type: 'main'
}

items: [{
    xtype: 'panel',
    bind: {
        title: '{name}'
    },
    region: 'west',
    html: '<ul><li>This area is commonly used for navigation, for example, using a "tree" component.</li></ul>',
    width: 250,
    split: true,
    tbar: [{
        text: 'Button',
        handler: 'onClickButton'
    }]
},{
    region: 'center',
    xtype: 'tabpanel',
    items:[{
        title: 'Tab 1',
        html: '<h2>Content appropriate for the current navigation.</h2>'
    }]
}]});

The main problem is that the window shows, but when trying to drag it, it disappears.. 主要问题是该窗口显示了,但是当尝试拖动它时,它消失了。

Thanks in advance! 提前致谢!

Found what the problem was. 找到了问题所在。 A window cannot be initiated as a viewport, therefor my advice to do what i did was create another view, which will be the window. 不能将窗口初始化为视口,因此我的建议是创建另一个视图,即窗口。 Then set the main view as viewport like so: 然后将主视图设置为视口,如下所示:

Ext.define('MyApp.view.main.Main', {
extend: 'Ext.container.Container',
plugins: 'viewport',
xtype: 'app-main'});

you can see that this view is only an empty container with no controllers or viewmodels attached. 您会看到此视图只是一个空容器,没有附加控制器或视图模型。 However, the application NEEDS a viewport. 但是,应用程序需要视口。

In the application.js we will make sure that our window will be loaded like so: 在application.js中,我们将确保窗口加载如下:

Ext.define('MyApp.Application', {
extend: 'Ext.app.Application',

name: 'MyApp',

stores: [
    // TODO: add global / shared stores here
],
views: [
    'MyApp.view.login.Login',
    'MyApp.view.main.Main'
],
launch: function () {

    Ext.widget('login');

}});

where 'login' is the xtype of the window view (in my case a login window form). 其中“ login”是窗口视图的xtype(在我的情况下是登录窗口形式)。 make sure this window has "autoShow: true" when you define it, else the window wont show up. 定义该窗口时,请确保该窗口具有“ autoShow:true”,否则该窗口将不会显示。

Finally we make sure we do not use the autocreateviewport by commenting this line. 最后,通过注释此行,确保不使用autocreateviewport。 the app.js will look like this now: app.js现在看起来像这样:

Ext.application({
name: 'MyApp',

extend: 'MyApp.Application'});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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