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

📄 combo.js

📁 Ext JS是一个创建丰富互联网应用程序的跨浏览器的JavaScrip库。它包含:高效率
💻 JS
📖 第 1 页 / 共 3 页
字号:
/*
 * Ext JS Library 3.0 Pre-alpha
 * Copyright(c) 2006-2008, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

/** * @class Ext.form.ComboBox * @extends Ext.form.TriggerField * <p>A combobox control with support for autocomplete, remote-loading, paging and many other features.</p> * <p>A ComboBox works in a similar manner to a traditional HTML &lt;select> field. The difference is * that to submit the {@link #valueField}, you must specify a {@link #hiddenName} to create a hidden input * field to hold the value of the valueField. The <i>{@link #displayField}</i> is shown in the text field * which is named according to the {@link #name}.</p> * <p><b><u>Events</u></b></p> * <p>To do something when something in ComboBox is selected, configure the select event:<pre><code> var cb = new Ext.form.ComboBox({    // all of your config options    listeners:{         scope: yourScope,         'select': yourFunction    }});// Alternatively, you can assign events after the object is created: var cb = new Ext.form.ComboBox(yourOptions);cb.on('select', yourFunction, yourScope); * </code></pre></p> *  * <p><b><u>ComboBox in Grid</u></b></p> * <p>If using a ComboBox in an {@link Ext.grid.EditorGridPanel Editor Grid} a {@link Ext.grid.Column#renderer renderer} * will be needed to show the displayField when the editor is not active.  Set up the renderer manually, or implement * a reusable render, for example:<pre><code> // create reusable rendererExt.util.Format.comboRenderer = function(combo){	return function(value){		var record = combo.findRecord(combo.{@link #valueField}, value);		return record ? record.get(combo.{@link #displayField}) : combo.{@link #valueNotFoundText};	}}// create the combo instancevar combo = new Ext.form.ComboBox({    {@link #typeAhead}: true,    {@link #triggerAction}: 'all',    {@link #lazyRender}:true,    {@link #mode}: 'local',    {@link #store}: new Ext.data.ArrayStore({        id: 0,        fields: [            'myId',            'displayText'        ],        data: [[1, 'item1'], [2, 'item2']]    }),    {@link #valueField}: 'myId',    {@link #displayField}: 'displayText'});// snippet of column model used within gridvar cm = new Ext.grid.ColumnModel([{       ...    },{       header: "Some Header",       dataIndex: 'whatever',       width: 130,       editor: combo, // specify reference to combo instance       renderer: Ext.util.Format.comboRenderer(combo) // pass combo instance to reusable renderer    },    ...]); * </code></pre></p> *  * <p><b><u>Filtering</u></b></p> * <p>A ComboBox {@link #doQuery uses filtering itself}, for information about filtering the ComboBox * store manually see <tt>{@link #lastQuery}</tt>.</p>  * @constructor * Create a new ComboBox. * @param {Object} config Configuration options * @xtype combo */Ext.form.ComboBox = Ext.extend(Ext.form.TriggerField, {    /**     * @cfg {Mixed} transform The id, DOM node or element of an existing HTML SELECT to convert to a ComboBox.     * Note that if you specify this and the combo is going to be in an {@link Ext.form.BasicForm} or     * {@link Ext.form.FormPanel}, you must also set <tt>{@link #lazyRender} = true</tt>.     */    /**     * @cfg {Boolean} lazyRender <tt>true</tt> to prevent the ComboBox from rendering until requested      * (should always be used when rendering into an {@link Ext.Editor} (eg. {@link Ext.grid.EditorGridPanel Grids}),     * defaults to <tt>false</tt>).     */    /**     * @cfg {String/Object} autoCreate <p>A {@link Ext.DomHelper DomHelper} element spec, or <tt>true</tt> for a default     * element spec. Used to create the {@link Ext.Component#getEl Element} which will encapsulate this Component.     * See <tt>{@link Ext.Component#autoEl autoEl}</tt> for details.  Defaults to:</p>     * <pre><code>{tag: "input", type: "text", size: "24", autocomplete: "off"}</code></pre>     */    /**     * @cfg {Ext.data.Store/Array} store The data source to which this combo is bound (defaults to <tt>undefined</tt>).     * Acceptable values for this property are:     * <div class="mdetail-params"><ul>     * <li><b>any {@link Ext.data.Store Store} subclass</b></li>     * <li><b>an Array</b> : Arrays will be converted to a {@link Ext.data.ArrayStore} internally.     * <div class="mdetail-params"><ul>     * <li><b>1-dimensional array</b> : (e.g., <tt>['Foo','Bar']</tt>)<div class="sub-desc">     * A 1-dimensional array will automatically be expanded (each array item will be the combo     * {@link #valueField value} and {@link #displayField text})</div></li>     * <li><b>2-dimensional array</b> : (e.g., <tt>[['f','Foo'],['b','Bar']]</tt>)<div class="sub-desc">     * For a multi-dimensional array, the value in index 0 of each item will be assumed to be the combo     * {@link #valueField value}, while the value at index 1 is assumed to be the combo {@link #displayField text}.     * </div></li></ul></div></li></ul></div>     * <p>See also <tt>{@link #mode}</tt>.</p>     */    /**     * @cfg {String} title If supplied, a header element is created containing this text and added into the top of     * the dropdown list (defaults to undefined, with no header element)     */    // private    defaultAutoCreate : {tag: "input", type: "text", size: "24", autocomplete: "off"},    /**     * @cfg {Number} listWidth The width (used as a parameter to {@link Ext.Element#setWidth}) of the dropdown     * list (defaults to the width of the ComboBox field).  See also <tt>{@link #minListWidth}     */    /**     * @cfg {String} displayField The underlying {@link Ext.data.Field#name data field name} to bind to this     * ComboBox (defaults to undefined if <tt>{@link #mode} = 'remote'</tt> or <tt>'text'</tt> if      * {@link #transform transforming a select} a select).     * <p>See also <tt>{@link #valueField}</tt>.</p>     * <p><b>Note</b>: if using a ComboBox in an {@link Ext.grid.EditorGridPanel Editor Grid} a     * {@link Ext.grid.Column#renderer renderer} will be needed to show the displayField when the editor is not     * active.</p>     */    /**     * @cfg {String} valueField The underlying {@link Ext.data.Field#name data value name} to bind to this     * ComboBox (defaults to undefined if <tt>{@link #mode} = 'remote'</tt> or <tt>'value'</tt> if     * {@link #transform transforming a select}).     * <p><b>Note</b>: use of a <tt>valueField</tt> requires the user to make a selection in order for a value to be     * mapped.  See also <tt>{@link #hiddenName}</tt>, <tt>{@link #hiddenValue}</tt>, and <tt>{@link #displayField}</tt>.</p>     */    /**     * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the     * field's data value (defaults to the underlying DOM element's name). Required for the combo's value to automatically     * post during a form submission.  See also {@link #valueField}.     * <p><b>Note</b>: the hidden field's id will also default to this name if {@link #hiddenId} is not specified.     * The ComboBox {@link Ext.Component#id id} and the <tt>{@link #hiddenId}</tt> <b>should be different</b>, since     * no two DOM nodes should share the same id.  So, if the ComboBox <tt>{@link Ext.form.Field#name name}</tt> and     * <tt>hiddenName</tt> are the same, you should specify a unique <tt>{@link #hiddenId}</tt>.</p>     */    /**     * @cfg {String} hiddenId If <tt>{@link #hiddenName}</tt> is specified, <tt>hiddenId</tt> can also be provided     * to give the hidden field a unique id (defaults to the <tt>{@link #hiddenName}</tt>).  The <tt>hiddenId</tt>     * and combo {@link Ext.Component#id id} should be different, since no two DOM     * nodes should share the same id.     */    /**     * @cfg {String} hiddenValue Sets the initial value of the hidden field if {@link #hiddenName} is     * specified to contain the selected {@link #valueField}, from the Store. Defaults to the configured     * <tt>{@link Ext.form.Field#value value}</tt>.     */    /**     * @cfg {String} listClass The CSS class to add to the predefined <tt>'x-combo-list'</tt> class     * applied the dropdown list element (defaults to '').      */    listClass : '',    /**     * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list     * (defaults to <tt>'x-combo-selected'</tt>)     */    selectedClass : 'x-combo-selected',    /**     * @cfg {String} listEmptyText The empty text to display in the data view if no items are found.     * (defaults to '')     */    listEmptyText: '',    /**     * @cfg {String} triggerClass An additional CSS class used to style the trigger button.  The trigger will always     * get the class <tt>'x-form-trigger'</tt> and <tt>triggerClass</tt> will be <b>appended</b> if specified     * (defaults to <tt>'x-form-arrow-trigger'</tt> which displays a downward arrow icon).     */    triggerClass : 'x-form-arrow-trigger',    /**     * @cfg {Boolean/String} shadow <tt>true</tt> or <tt>"sides"</tt> for the default effect, <tt>"frame"</tt> for     * 4-way shadow, and <tt>"drop"</tt> for bottom-right     */    shadow : 'sides',    /**     * @cfg {String} listAlign A valid anchor position value. See <tt>{@link Ext.Element#alignTo}</tt> for details     * on supported anchor positions (defaults to <tt>'tl-bl?'</tt>)     */    listAlign : 'tl-bl?',    /**     * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown     * (defaults to <tt>300</tt>)     */    maxHeight : 300,    /**     * @cfg {Number} minHeight The minimum height in pixels of the dropdown list when the list is constrained by its     * distance to the viewport edges (defaults to <tt>90</tt>)     */    minHeight : 90,    /**     * @cfg {String} triggerAction The action to execute when the trigger is clicked.     * <div class="mdetail-params"><ul>     * <li><b><tt>'query'</tt></b> : <b>Default</b>     * <p class="sub-desc">{@link #doQuery run the query} using the {Ext.form.Field#getRawValue raw value}</p></li>     * <li><b><tt>'all'</tt></b> :      * <p class="sub-desc">{@link #doQuery run the query} specified by the <tt>{@link #allQuery}</tt> config option</p></li>     * </ul></div>     */    triggerAction : 'query',    /**     * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and     * {@link #typeAhead} activate (defaults to <tt>4</tt> if <tt>{@link #mode} = 'remote'</tt> or <tt>0</tt> if     * <tt>{@link #mode} = 'local'</tt>, does not apply if      * <tt>{@link Ext.form.TriggerField#editable editable} = false</tt>).     */    minChars : 4,    /**     * @cfg {Boolean} typeAhead <tt>true</tt> to populate and autoselect the remainder of the text being     * typed after a configurable delay ({@link #typeAheadDelay}) if it matches a known value (defaults     * to <tt>false</tt>)     */    typeAhead : false,    /**     * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and     * sending the query to filter the dropdown list (defaults to <tt>500</tt> if <tt>{@link #mode} = 'remote'</tt>     * or <tt>10</tt> if <tt>{@link #mode} = 'local'</tt>)     */    queryDelay : 500,    /**     * @cfg {Number} pageSize If greater than <tt>0</tt>, a {@link Ext.PagingToolbar} is displayed in the     * footer of the dropdown list and the {@link #doQuery filter queries} will execute with page start and     * {@link Ext.PagingToolbar#pageSize limit} parameters. Only applies when <tt>{@link #mode} = 'remote'</tt>     * (defaults to <tt>0</tt>).     */    pageSize : 0,    /**     * @cfg {Boolean} selectOnFocus <tt>true</tt> to select any existing text in the field immediately on focus.     * Only applies when <tt>{@link Ext.form.TriggerField#editable editable} = true</tt> (defaults to     * <tt>false</tt>).     */    selectOnFocus : false,    /**     * @cfg {String} queryParam Name of the query ({@link Ext.data.Store#baseParam baseParam} name for the store)     * as it will be passed on the querystring (defaults to <tt>'query'</tt>)     */    queryParam : 'query',    /**     * @cfg {String} loadingText The text to display in the dropdown list while data is loading.  Only applies     * when <tt>{@link #mode} = 'remote'</tt> (defaults to <tt>'Loading...'</tt>)     */    loadingText : 'Loading...',    /**     * @cfg {Boolean} resizable <tt>true</tt> to add a resize handle to the bottom of the dropdown list     * (creates an {@link Ext.Resizable} with 'se' {@link Ext.Resizable#pinned pinned} handles).     * Defaults to <tt>false</tt>.     */    resizable : false,    /**     * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if     * <tt>{@link #resizable} = true</tt> (defaults to <tt>8</tt>)     */    handleHeight : 8,    /**     * @cfg {String} allQuery The text query to send to the server to return all records for the list     * with no filtering (defaults to '')     */    allQuery: '',    /**     * @cfg {String} mode Acceptable values are:     * <div class="mdetail-params"><ul>     * <li><b><tt>'remote'</tt></b> : <b>Default</b>     * <p class="sub-desc">Automatically loads the <tt>{@link #store}</tt> the <b>first</b> time the trigger     * is clicked. If you do not want the store to be automatically loaded the first time the trigger is     * clicked, set to <tt>'local'</tt> and manually load the store.  To force a requery of the store     * <b>every</b> time the trigger is clicked see <tt>{@link #lastQuery}</tt>.</p></li>     * <li><b><tt>'local'</tt></b> :      * <p class="sub-desc">ComboBox loads local data</p>     * <pre><code>var combo = new Ext.form.ComboBox({    renderTo: document.body,    mode: 'local',    store: new Ext.data.ArrayStore({        id: 0,        fields: [            'myId',  // numeric value is the key            'displayText'        ],        data: [[1, 'item1'], [2, 'item2']]  // data is local    }),    valueField: 'myId',    displayField: 'displayText',    triggerAction: 'all'});     * </code></pre></li>     * </ul></div>     */    mode: 'remote',    /**     * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to <tt>70</tt>, will     * be ignored if <tt>{@link #listWidth}</tt> has a higher value)     */    minListWidth : 70,    /**     * @cfg {Boolean} forceSelection <tt>true</tt> to restrict the selected value to one of the values in the list,     * <tt>false</tt> to allow the user to set arbitrary text into the field (defaults to <tt>false</tt>)     */    forceSelection : false,    /**     * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed     * if <tt>{@link #typeAhead} = true</tt> (defaults to <tt>250</tt>)     */    typeAheadDelay : 250,    /**     * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in     * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined). If this     * default text is used, it means there is no value set and no validation will occur on this field.     */    /**     * @cfg {Boolean} lazyInit <tt>true</tt> to not initialize the list for this combo until the field is focused     * (defaults to <tt>true</tt>)     */    lazyInit : true,    /**     * The value of the match string used to filter the store. Delete this property to force a requery.     * Example use:     * <pre><code>var combo = new Ext.form.ComboBox({    ...    mode: 'remote',    ...    listeners: {        // delete the previous query in the beforequery event or set         // combo.lastQuery = null (this will reload the store the next time it expands)        beforequery: function(qe){            delete qe.combo.lastQuery;        }    }});     * </code></pre>     * To make sure the filter in the store is not cleared the first time the ComboBox trigger is used     * configure the combo with <tt>lastQuery=''</tt>. Example use:     * <pre><code>var combo = new Ext.form.ComboBox({    ...    mode: 'local',    triggerAction: 'all',    lastQuery: '' });     * </code></pre>     * @property lastQuery     * @type String     */    // private    initComponent : function(){        Ext.form.ComboBox.superclass.initComponent.call(this);        this.addEvents(            /**             * @event expand             * Fires when the dropdown list is expanded             * @param {Ext.form.ComboBox} combo This combo box             */            'expand',            /**             * @event collapse             * Fires when the dropdown list is collapsed             * @param {Ext.form.ComboBox} combo This combo box             */            'collapse',            /**             * @event beforeselect             * Fires before a list item is selected. Return false to cancel the selection.             * @param {Ext.form.ComboBox} combo This combo box             * @param {Ext.data.Record} record The data record returned from the underlying store             * @param {Number} index The index of the selected item in the dropdown list             */            'beforeselect',            /**             * @event select             * Fires when a list item is selected             * @param {Ext.form.ComboBox} combo This combo box             * @param {Ext.data.Record} record The data record returned from the underlying store             * @param {Number} index The index of the selected item in the dropdown list             */            'select',            /**             * @event beforequery             * Fires before all queries are processed. Return false to cancel the query or set the queryEvent's             * cancel property to true.             * @param {Object} queryEvent An object that has these properties:<ul>             * <li><code>combo</code> : Ext.form.ComboBox <div class="sub-desc">This combo box</div></li>             * <li><code>query</code> : String <div class="sub-desc">The query</div></li>             * <li><code>forceAll</code> : Boolean <div class="sub-desc">True to force "all" query</div></li>             * <li><code>cancel</code> : Boolean <div class="sub-desc">Set to true to cancel the query</div></li>             * </ul>             */            'beforequery'        );

⌨️ 快捷键说明

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