网上下载的一个多选下拉框js,其他都能正常使用,但是我在进行一条记录修改时,页面上能显示下拉框的值,但是点击下拉框发现选项不是选中状态。[img]C:\Documents and Settings\Administrator\桌面\QQ图片20140424113645.jpg[/img]
多选下拉框代码如下:
// vim: ts=4:sw=4:nu:fdc=4:nospell
/**
* Ext.form.MultiSelect, List of Values Combo
*
* @author Ing. Jozef Sakáloš
* @copyright (c) 2008, by Ing. Jozef Sakáloš
* @date 16. April 2008
* @version $Id: Ext.form.MultiSelect.js 291 2008-07-03 07:46:49Z jozo $
*
* @license Ext.form.MultiSelect.js is licensed under the terms of the Open Source
* LGPL 3.0 license. Commercial use is permitted to the extent that the
* code/component(s) do NOT become part of another Open Source or Commercially
* licensed development library or toolkit without explicit permission.
*
* License details: http://www.gnu.org/licenses/lgpl.html
*/
/*global Ext */
// add RegExp.escape if it has not been already added
if('function' !== typeof RegExp.escape) {
RegExp.escape = function(s) {
if('string' !== typeof s) {
return s;
}
// Note: if pasting from forum, precede ]/\ with backslash manually
return s.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
}; // eo function escape
}
// create namespace
Ext.ns('Ext.form');
/**
*
* @class Ext.form.MultiSelect
* @extends Ext.form.ComboBox
*/
Ext.form.MultiSelect = Ext.extend(Ext.form.ComboBox, {
// {{{
// configuration options
/**
* @cfg {String} checkField name of field used to store checked state.
* It is automatically added to existing fields.
* Change it only if it collides with your normal field.
*/
checkField:'checked'
/**
* @cfg {String} separator separator to use between values and texts
*/
,separator:','
/**
* @cfg {String/Array} tpl Template for items.
* Change it only if you know what you are doing.
*/
// }}}
// {{{
,initComponent:function() {
// template with checkbox
if(!this.tpl) {
this.tpl =
'<tpl for=".">'
+'<div class="x-combo-list-item">'
+'<img src="' + Ext.BLANK_IMAGE_URL + '" '
+'class="ux-MultiSelect-icon ux-MultiSelect-icon-'
+'{[values.' + this.checkField + '?"checked":"unchecked"' + ']}">'
+'<div class="ux-MultiSelect-item-text">{' + (this.displayField || 'text' )+ '}</div>'
+'</div>'
+'</tpl>'
;
}
// call parent
Ext.form.MultiSelect.superclass.initComponent.apply(this, arguments);
// install internal event handlers
this.on({
scope:this
,beforequery:this.onBeforeQuery
,blur:this.onRealBlur
});
// remove selection from input field
this.onLoad = this.onLoad.createSequence(function() {
if(this.el) {
var v = this.el.dom.value;
this.el.dom.value = '';
this.el.dom.value = v;
}
});
} // e/o function initComponent
// }}}
// {{{
/**
* Disables default tab key bahavior
* @private
*/
,initEvents:function() {
Ext.form.MultiSelect.superclass.initEvents.apply(this, arguments);
// disable default tab handling - does no good
this.keyNav.tab = false;
} // eo function initEvents
// }}}
// {{{
/**
* clears value
*/
,clearValue:function() {
this.value = '';
this.setRawValue(this.value);
this.store.clearFilter();
this.store.each(function(r) {
r.set(this.checkField, false);
}, this);
if(this.hiddenField) {
this.hiddenField.value = '';
}
this.applyEmptyText();
} // eo function clearValue
// }}}
// {{{
/**
* @return {String} separator (plus space) separated list of selected displayFields
* @private
*/
,getCheckedDisplay:function() {
var re = new RegExp(this.separator, "g");
return this.getCheckedValue(this.displayField).replace(re, this.separator + ' ');
} // eo function getCheckedDisplay
// }}}
// {{{
/**
* @return {String} separator separated list of selected valueFields
* @private
*/
,getCheckedValue:function(field) {
field = field || this.valueField;
var c = [];
// store may be filtered so get all records
var snapshot = this.store.snapshot || this.store.data;
snapshot.each(function(r) {
if(r.get(this.checkField)) {
c.push(r.get(field));
}
}, this);
return c.join(this.separator);
} // eo function getCheckedValue
// }}}
// {{{
/**
* beforequery event handler - handles multiple selections
* @param {Object} qe query event
* @private
*/
,onBeforeQuery:function(qe) {
qe.query = qe.query.replace(new RegExp(RegExp.escape(this.getCheckedDisplay()) + '[ ' + this.separator + ']*'), '');
} // eo function onBeforeQuery
// }}}
// {{{
/**
* blur event handler - runs only when real blur event is fired
*/
,onRealBlur:function() {
this.list.hide();
var rv = this.getRawValue();
var rva = rv.split(new RegExp(RegExp.escape(this.separator) + ' *'));
var va = [];
var snapshot = this.store.snapshot || this.store.data;
// iterate through raw values and records and check/uncheck items
Ext.each(rva, function(v) {
snapshot.each(function(r) {
if(v === r.get(this.displayField)) {
va.push(r.get(this.valueField));
}
}, this);
}, this);
this.setValue(va.join(this.separator));
this.store.clearFilter();
} // eo function onRealBlur
// }}}
// {{{
/**
* Combo's onSelect override
* @private
* @param {Ext.data.Record} record record that has been selected in the list
* @param {Number} index index of selected (clicked) record
*/
,onSelect:function(record, index) {
if(this.fireEvent('beforeselect', this, record, index) !== false){
// toggle checked field
record.set(this.checkField, !record.get(this.checkField));
// display full list
if(this.store.isFiltered()) {
this.doQuery(this.allQuery);
}
// set (update) value and fire event
this.setValue(this.getCheckedValue());
this.fireEvent('select', this, record, index);
}
} // eo function onSelect
// }}}
// {{{
/**
* Sets the value of the MultiSelect
* @param {Mixed} v value
*/
,setValue:function(v) {
if(v) {
v = '' + v;
if(this.valueField) {
this.store.clearFilter();
this.store.each(function(r) {
var checked = !(!v.match(
'(^|' + this.separator + ')' + RegExp.escape(r.get(this.valueField))
+'(' + this.separator + '|$)'))
;
r.set(this.checkField, checked);
}, this);
this.value = this.getCheckedValue();
this.setRawValue(this.getCheckedDisplay());
if(this.hiddenField) {
this.hiddenField.value = this.value;
}
}
else {
this.value = v;
this.setRawValue(v);
if(this.hiddenField) {
this.hiddenField.value = v;
}
}
if(this.el) {
this.el.removeClass(this.emptyClass);
}
}
else {
this.clearValue();
}
} // eo function setValue
// }}}
// {{{
/**
* Selects all items
*/
,selectAll:function() {
this.store.each(function(record){
// toggle checked field
record.set(this.checkField, true);
}, this);
//display full list
this.doQuery(this.allQuery);
this.setValue(this.getCheckedValue());
} // eo full selectAll
// }}}
// {{{
/**
* Deselects all items. Synonym for clearValue
*/
,deselectAll:function() {
this.clearValue();
} // eo full deselectAll
// }}}
}); // eo extend
// register xtype
Ext.reg('multiSelect', Ext.form.MultiSelect);
相关推荐
然而,标准的ExtJS下拉框只支持单选模式。为了实现多选功能,我们需要对其进行扩展。这个“extjs多选 下拉框扩展”就是解决这个问题的一种方案。 首先,我们要理解ExtJS的ComboBox的基本结构。ComboBox由一个输入框...
在EXTJS框架中,"多选下拉框"(Multi-Select ComboBox)是一种常见的组件,它允许用户在下拉列表中选择多个选项。EXTJS 3.*版本也提供了这种功能,使得开发者能够创建功能丰富的界面,提升用户体验。下面将详细解释...
在ExtJS 3.4.0版本中,多选下拉框(Multiselect Combobox)是一种常见的用户界面组件,用于提供多个选项供用户选择。这个功能增强了标准的单选下拉框,允许用户同时选择多个条目,通常通过复选框实现。在描述中提到...
在EXTJS中,多选下拉框(Lovcombo)是一种常见的组件,它结合了选择列表和输入框的功能,允许用户从预定义的选项中选择多个条目。这个lovcombo是lov(List-Value)和combo(组合框)的结合体,提供了丰富的交互性和...
在ExtJS 3中,多选下拉框(LovCombo)是一种复合组件,它结合了下拉列表和“爱好者选择”(LOV,Lookup Value)的功能,允许用户在多个选项中进行复选选择。在Web应用中,这种组件常用于数据输入,特别是在数据库...
首先,创建一个基本的EXTJS下拉框需要定义`Ext.form.field.ComboBox`对象。以下是一个简单的示例: ```javascript Ext.application({ name: 'MyApp', launch: function () { Ext.create('Ext.container.Viewport...
本文将深入探讨如何在ExtJS中实现多选下拉框功能,这在数据输入和选择场景中非常常见。我们将基于标题中的“3个代码”来讲解不同的实现方法,并结合提供的资源`demo`进行说明。 1. **ExtJS的MultiSelect ComboBox**...
在EXTJS中, Combo(组合框)是一个常用的组件,它可以作为单选或多选的下拉框使用。本示例将详细讲解EXTJS中实现多选下拉框的代码及实践。 在"ext多选下拉框(代码及例子)"这个主题中,主要涉及到的知识点有: 1....
在本篇中,我们将深入探讨如何在ExtJS中实现下拉框的多选功能。 首先,了解基本的ExtJS ComboBox。ComboBox 是一个具有搜索功能的下拉列表,用户可以从中选择一个选项。它由两个主要部分组成:一个可编辑的输入字段...
该资源主要展示了在Extjs6中Combobox控件实现下拉选择多个数据的功能
本篇将重点讲解ExtJS中的一个扩展组件——多选下拉框,即“combobox”。 在ExtJS中,ComboBox是一个基本的输入组件,它结合了文本输入框和下拉列表的功能。默认情况下,ComboBox只允许用户选择一个选项。但是,通过...
最近小弟做了Extjs实现实现下拉框联动的效果,参考了好久才学会,闲下来发一个简单的例子。。呵呵
在这个特定的情况下,我们讨论的是一个定制的下拉树菜单控件——ComboBoxTree,它在ExtJS4中实现了单选和多选功能,并且具备展开选中指定节点的能力。这个控件在实际项目中已经被广泛使用并证明了其稳定性和实用性,...
在EXTJS4中,ComboBox是一个常用的组件,它用于创建下拉选择框,通常用于输入框的辅助选择。这个组件提供了一种用户友好的方式来从一组预定义的选项中进行选择。然而,根据你的标题和描述,你似乎遇到了一个特别的...
1. **配置多选**:通过设置`multiSelect: true`属性,可以让ComboBox支持多选模式。用户可以通过Ctrl或Shift键进行多选。 2. **实时搜索**:实现搜索功能需要监听ComboBox的`keyup`事件,并在此事件处理器中应用...
"ext4实现带复选框的多选下拉框"这个主题聚焦于如何在EXTJS 4框架中构建一个功能丰富的UI组件,它允许用户通过复选框进行多选操作,提升用户体验。EXTJS是一个流行的JavaScript库,提供了丰富的组件库来构建复杂的...
在压缩包子文件的文件名称列表中提到的"extjs下拉",很可能包含了EXTJS下拉框相关的示例代码、样式文件或者配置文件。这些文件可以帮助开发者理解并应用`Ext.ux.form.LovCombo`,通过查看源码学习如何初始化、配置...
本方法和用checkbox, listbox等控件和事件拼凑出来的不同,本方法是一个集成的独立控件,基本实现了控件的顺滑度,下拉框可悬浮等效果,可以认为是comboBox的升级版,使用方便,仅需引用编译好的DLL,直接在toolBox...