簡體   English   中英

Extjs 4:使用ux.center

[英]Extjs 4: use ux.center

我在使用自定義布局ux.center時遇到了麻煩。 我在做Ext.Loader或Ext.require錯了嗎? Center.js文件位於/var/www/application/ux/layout/Center.js下,此文件(app.js)位於/var/wwww/application/app.js下

Ext.Loader.setPath('Ext.ux', '/var/www/application/ux');
Ext.require('Ext.ux.layout.Center');
Ext.application({
    name: 'AM',
    appFolder: 'app',
    controllers: ['Users'],
    launch: function(){
            Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider'));
            Ext.create('Ext.container.Viewport', {
                    width: 1150,
                    height: 'auto',
                    autoScroll: 'true',
                    layout: 'anchor',
                    items:[{xtype: 'userpanel'},
                    {
                            xtype: 'panel',
                            width: 1150,
                            layout:'ux.center',
                            items:[{ 
                                    xtype: 'panel',
                                    width: 1150,
                                    widthRatio: .75,
                                    items: [{
                                            xtype: 'userbutton',
                                            action: '',
                                            text: 'Print'
                                    },
                                    {
                                            xtype: 'userbutton',
                                            action: '',
                                            text: 'Download'
                                    },
                                    {
                                            xtype: 'userbutton',
                                            action: 'chart',
                                            text: 'Chart!'
                                    }]
                            }]}]
            });
}});

感謝您提供有關使此布局正常工作的任何提示

你應該在extjs加載/var/www/application/ux/layout/Center.js腳本后運行Ext.application方法。 為此,只需使用Ext.onReady添加回調

Ext.Loader.setPath('Ext.ux', '/var/www/application/ux');
Ext.require('Ext.ux.layout.Center');

Ext.onReady(function () {
    Ext.application({ ... });
});

但正確的方法是使用“requires”配置屬性

Ext.application({
    requires: ['Ext.ux.layout.Center'],
    name: 'AM',
    appFolder: 'app',        
    controllers: ['Users'],
    launch: function(){
            Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider'));
            Ext.create('Ext.container.Viewport', {
                    width: 1150,
                    height: 'auto',
                    autoScroll: 'true',
                    layout: 'anchor',
                    items:[{xtype: 'userpanel'},
                    {
                            xtype: 'panel',
                            width: 1150,
                            layout:'ux.center',
                            items:[{ 
                                    xtype: 'panel',
                                    width: 1150,
                                    widthRatio: .75,
                                    items: [{
                                            xtype: 'userbutton',
                                            action: '',
                                            text: 'Print'
                                    },
                                    {
                                            xtype: 'userbutton',
                                            action: '',
                                            text: 'Download'
                                    },
                                    {
                                            xtype: 'userbutton',
                                            action: 'chart',
                                            text: 'Chart!'
                                    }]
                            }]}]
            });
}});

您還可以閱讀以下材料http://docs.sencha.com/ext-js/4-1/#!/api/Ext.app.Application

您還可以為視口創建自己的類,並將其放在[appFolder] / view /文件夾中

Ext.define('AM.view.Viewport', {
    extend: 'Ext.view.Viewport',

    requires: ['Ext.ux.layout.Center'],

    width: 1150,
    height: 'auto',
    autoScroll: 'true',
    layout: 'anchor',

    initComponent: function () {
        this.items = [{
            xtype: 'userpanel'
        }, {
            xtype: 'panel',
            width: 1150,
            layout:'ux.center',
            items:[{ 
                xtype: 'panel',
                width: 1150,
                widthRatio: .75,
                items: [{
                    xtype: 'userbutton',
                    action: '',
                    text: 'Print'
                }, {
                    xtype: 'userbutton',
                    action: '',
                    text: 'Download'
                }, {
                    xtype: 'userbutton',
                    action: 'chart',
                    text: 'Chart!'
                }]
            }]
        }];
        this.callParent();
    }
});

並使用Ext.app.Application配置屬性autoCreateViewport 它將加載[appFolder] /view/Viewport.js腳本並將其用作視口

Ext.application({
    name: 'AM',
    appFolder: **insert you app folder path here**, // in you case it will be 'application'       
    controllers: ['Users'],
    autoCreateViewport: true
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM