⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 container.js

📁 ext-2.3.0
💻 JS
📖 第 1 页 / 共 2 页
字号:
/*
 * Ext JS Library 2.3.0
 * Copyright(c) 2006-2009, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

/** * @class Ext.Container * @extends Ext.BoxComponent * <p>Base class for any {@link Ext.BoxComponent} that can contain other components. The most commonly * used Container classes are {@link Ext.Panel}, {@link Ext.Window} and {@link Ext.TabPanel}, but you can * create a lightweight Container to encapsulate an HTML element that is created to your * specifications at render time by using the {@link Ext.Component#autoEl autoEl} config option * which takes the form of a {@link Ext.DomHelper DomHelper} specification. If you do not need * the capabilities offered by the above mentioned classes, for instance embedded * {@link Ext.layout.ColumnLayout column} layouts inside FormPanels, then this is a useful technique.</p> * <p>The code below illustrates both how to explicitly <i>create</i> a Container, and how to implicitly * create one using the <b><tt>'container'</tt></b> xtype:<pre><code>var embeddedColumns = new Ext.Container({    autoEl: {},    layout: 'column',    defaults: {        xtype: 'container',        autoEl: {},        layout: 'form',        columnWidth: 0.5,        style: {            padding: '10px'        }    },    items: [{        items: {            xtype: 'datefield',            name: 'startDate',            fieldLabel: 'Start date'        }    }, {        items: {            xtype: 'datefield',            name: 'endDate',            fieldLabel: 'End date'        }    }]});</code></pre></p> * Containers handle the basic behavior of containing items, namely adding, inserting and removing them. * The specific layout logic required to visually render contained items is delegated to any one of the different * {@link #layout} classes available.</p> * <p>When either specifying child {@link #items} of a Container, or dynamically adding components to a Container, * remember to consider how you wish the Container to arrange those child elements, and whether those child elements * need to be sized using one of Ext's built-in layout schemes.</p> * <p>By default, Containers use the {@link Ext.layout.ContainerLayout ContainerLayout} scheme. This simply renders * child components, appending them one after the other inside the Container, and does not apply any sizing at all. * This is a common source of confusion when widgets like GridPanels or TreePanels are added to Containers for * which no layout has been specified. If a Container is left to use the ContainerLayout scheme, none of its child * components will be resized, or changed in any way when the Container is resized.</p> * <p>A very common example of this is where a developer will attempt to add a GridPanel to a TabPanel by wrapping * the GridPanel <i>inside</i> a wrapping Panel and add that wrapping Panel to the TabPanel. This misses the point that * Ext's inheritance means that a GridPanel <b>is</b> a Component which can be added unadorned into a Container. If * that wrapping Panel has no layout configuration, then the GridPanel will not be sized as expected.<p> * <p>Below is an example of adding a newly created GridPanel to a TabPanel. A TabPanel uses {@link Ext.layout.CardLayout} * as its layout manager which means all its child items are sized to fit exactly into its client area. The following * code requires prior knowledge of how to create GridPanels. See {@link Ext.grid.GridPanel}, {@link Ext.data.Store} * and {@link Ext.data.JsonReader} as well as the grid examples in the Ext installation's <tt>examples/grid</tt> * directory.</p><pre><code>//  Create the GridPanel.myGrid = new Ext.grid.GridPanel({    store: myStore,    columns: myColumnModel,    title: 'Results',});myTabPanel.add(myGrid);myTabPanel.setActiveTab(myGrid);</code></pre> */Ext.Container = Ext.extend(Ext.BoxComponent, {    /** @cfg {Boolean} monitorResize     * True to automatically monitor window resize events to handle anything that is sensitive to the current size     * of the viewport.  This value is typically managed by the chosen {@link #layout} and should not need to be set manually.     */    /**     * @cfg {String} layout     * The layout type to be used in this container.  If not specified, a default {@link Ext.layout.ContainerLayout}     * will be created and used. Specific config values for the chosen layout type can be specified using      * {@link #layoutConfig}. Valid values are:<ul class="mdetail-params">     * <li>absolute</li>     * <li>accordion</li>     * <li>anchor</li>     * <li>border</li>     * <li>card</li>     * <li>column</li>     * <li>fit</li>     * <li>form</li>     * <li>table</li></ul>     */    /**     * @cfg {Object} layoutConfig     * This is a config object containing properties specific to the chosen layout (to be used in conjunction with     * the {@link #layout} config value).  For complete details regarding the valid config options for each layout     * type, see the layout class corresponding to the type specified:<ul class="mdetail-params">     * <li>{@link Ext.layout.Absolute}</li>     * <li>{@link Ext.layout.Accordion}</li>     * <li>{@link Ext.layout.AnchorLayout}</li>     * <li>{@link Ext.layout.BorderLayout}</li>     * <li>{@link Ext.layout.CardLayout}</li>     * <li>{@link Ext.layout.ColumnLayout}</li>     * <li>{@link Ext.layout.FitLayout}</li>     * <li>{@link Ext.layout.FormLayout}</li>     * <li>{@link Ext.layout.TableLayout}</li></ul>     */    /**     * @cfg {Boolean/Number} bufferResize     * When set to true (100 milliseconds) or a number of milliseconds, the layout assigned for this container will buffer     * the frequency it calculates and does a re-layout of components. This is useful for heavy containers or containers     * with a large quantity of sub-components for which frequent layout calls would be expensive.     */    /**     * @cfg {String/Number} activeItem     * A string component id or the numeric index of the component that should be initially activated within the     * container's layout on render.  For example, activeItem: 'item-1' or activeItem: 0 (index 0 = the first     * item in the container's collection).  activeItem only applies to layout styles that can display     * items one at a time (like {@link Ext.layout.Accordion}, {@link Ext.layout.CardLayout} and     * {@link Ext.layout.FitLayout}).  Related to {@link Ext.layout.ContainerLayout#activeItem}.     */    /**     * @cfg {Mixed} items     * A single item, or an array of child Components to be added to this container.     * Each item can be any type of object based on {@link Ext.Component}.<br><br>     * Component config objects may also be specified in order to avoid the overhead     * of constructing a real Component object if lazy rendering might mean that the     * added Component will not be rendered immediately. To take advantage of this     * "lazy instantiation", set the {@link Ext.Component#xtype} config property to     * the registered type of the Component wanted.<br><br>     * For a list of all available xtypes, see {@link Ext.Component}.     * If a single item is being passed, it should be passed directly as an object     * reference (e.g., items: {...}).  Multiple items should be passed as an array     * of objects (e.g., items: [{...}, {...}]).     */    /**     * @cfg {Object} defaults     * A config object that will be applied to all components added to this container either via the {@link #items}     * config or via the {@link #add} or {@link #insert} methods.  The defaults config can contain any number of     * name/value property pairs to be added to each item, and should be valid for the types of items     * being added to the container.  For example, to automatically apply padding to the body of each of a set of     * contained {@link Ext.Panel} items, you could pass: defaults: {bodyStyle:'padding:15px'}.     */    /** @cfg {Boolean} autoDestroy     * If true the container will automatically destroy any contained component that is removed from it, else     * destruction must be handled manually (defaults to true).     */    autoDestroy: true,    /** @cfg {Boolean} hideBorders     * True to hide the borders of each contained component, false to defer to the component's existing     * border settings (defaults to false).     */    /** @cfg {String} defaultType     * <p>The default {@link Ext.Component xtype} of child Components to create in this Container when     * a child item is specified as a raw configuration object, rather than as an instantiated Component.</p>     * <p>Defaults to 'panel'.</p>     */    defaultType: 'panel',    // private    initComponent : function(){        Ext.Container.superclass.initComponent.call(this);        this.addEvents(            /**             * @event afterlayout             * Fires when the components in this container are arranged by the associated layout manager.             * @param {Ext.Container} this             * @param {ContainerLayout} layout The ContainerLayout implementation for this container             */            'afterlayout',            /**             * @event beforeadd             * Fires before any {@link Ext.Component} is added or inserted into the container.             * A handler can return false to cancel the add.             * @param {Ext.Container} this             * @param {Ext.Component} component The component being added             * @param {Number} index The index at which the component will be added to the container's items collection             */            'beforeadd',            /**             * @event beforeremove             * Fires before any {@link Ext.Component} is removed from the container.  A handler can return             * false to cancel the remove.             * @param {Ext.Container} this             * @param {Ext.Component} component The component being removed             */            'beforeremove',            /**             * @event add             * Fires after any {@link Ext.Component} is added or inserted into the container.             * @param {Ext.Container} this             * @param {Ext.Component} component The component that was added             * @param {Number} index The index at which the component was added to the container's items collection             */            'add',            /**             * @event remove             * Fires after any {@link Ext.Component} is removed from the container.             * @param {Ext.Container} this             * @param {Ext.Component} component The component that was removed             */            'remove'        );        /**         * The collection of components in this container as a {@link Ext.util.MixedCollection}         * @type MixedCollection         * @property items         */        var items = this.items;        if(items){            delete this.items;            if(Ext.isArray(items)){                if(items.length > 0){                    this.add.apply(this, items);                }            }else{                this.add(items);            }        }    },    // private    initItems : function(){        if(!this.items){            this.items = new Ext.util.MixedCollection(false, this.getComponentId);            this.getLayout(); // initialize the layout        }    },    // private    setLayout : function(layout){        if(this.layout && this.layout != layout){            this.layout.setContainer(null);        }        this.initItems();        this.layout = layout;        layout.setContainer(this);    },    // private    render : function(){        Ext.Container.superclass.render.apply(this, arguments);        if(this.layout){            if(typeof this.layout == 'string'){                this.layout = new Ext.Container.LAYOUTS[this.layout.toLowerCase()](this.layoutConfig);            }            this.setLayout(this.layout);            if(this.activeItem !== undefined){                var item = this.activeItem;                delete this.activeItem;                this.layout.setActiveItem(item);                return;            }        }        if(!this.ownerCt){            this.doLayout();        }        if(this.monitorResize === true){            Ext.EventManager.onWindowResize(this.doLayout, this, [false]);        }    },    /**     * <p>Returns the Element to be used to contain the child Components of this Container.</p>     * <p>An implementation is provided which returns the Container's {@link #getEl Element}, but     * if there is a more complex structure to a Container, this may be overridden to return     * the element into which the {@link #layout layout} renders child Components.</p>     * @return {Ext.Element} The Element to render child Components into.     */    getLayoutTarget : function(){        return this.el;    },    // private - used as the key lookup function for the items collection    getComponentId : function(comp){        return comp.itemId || comp.id;    },    /**     * <p>Adds a {@link Ext.Component Component} to this Container. Fires the {@link #beforeadd} event before     * adding, then fires the {@link #add} event after the component has been added.</p>     * <p>You will never call the render method of a child Component when using a Container.     * Child Components are rendered by this Container's {@link #layout} manager when     * this Container is first rendered.</p>     * <p>Certain layout managers allow dynamic addition of child components. Those that do     * include {@link Ext.layout.CardLayout}, {@link Ext.layout.AnchorLayout},     * {@link Ext.layout.FormLayout}, {@link Ext.layout.TableLayout}.</p>     * <p>If the Container is already rendered when add is called, you may need to call     * {@link #doLayout} to refresh the view which causes any unrendered child Components     * to be rendered. This is required so that you can add multiple child components if needed     * while only refreshing the layout once.</p>     * <p>When creating complex UIs, it is important to remember that sizing and positioning     * of child items is the responsibility of the Container's {@link #layout} manager. If     * you expect child items to be sized in response to user interactions, you must     * specify a layout manager which creates and manages the type of layout you have in mind.</p>     * <p><b>Omitting the {@link #layout} config means that a basic layout manager is     * used which does nothnig but render child components sequentially into the Container.     * No sizing or positioning will be performed in this situation.</b></p>     * @param {Ext.Component/Object} component The Component to add.<br><br>     * Ext uses lazy rendering, and will only render the added Component should     * it become necessary, that is: when the Container is layed out either on first render     * or in response to a {@link #doLayout} call.<br><br>     * A Component config object may be passed instead of an instantiated Component object.     * The type of Component created from a config object is determined by the {@link Ext.Component#xtype xtype}     * config property. If no xtype is configured, the Container's {@link #defaultType}     * is used.<br><br>     * For a list of all available xtypes, see {@link Ext.Component}.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -