IconCombobox 代码:
Ext.ux.IconCombo = Ext.extend(Ext.form.ComboBox, {
initComponent:function() {
Ext.apply(this, {
tpl: '<tpl for=".">'
+ '<div class="x-combo-list-item ux-icon-combo-item '
+ '{' + this.iconClsField + '}">'
+ '{' + this.displayField + '}'
+ '</div></tpl>'
});
// call parent initComponent
Ext.ux.IconCombo.superclass.initComponent.call(this);
}, // end of function initComponent
on
// call parent on
Ext.ux.IconCombo.superclass.on
// adjust styles
this.wrap.applyStyles({position:'relative'});
this.el.addClass('ux-icon-combo-input');
// add div for icon
this.icon = Ext.DomHelper.append(this.el.up('div.x-form-field-wrap'), {
tag: 'div', style:'position:absolute'
});
}, // end of function on
setIconCls:function() {
var rec = this.store.query(this.valueField, this.getValue()).itemAt(0);
if(rec) {
this.icon.className = 'ux-icon-combo-icon ' + rec.get(this.iconClsField);
}
}, // end of function setIconCls
setValue: function(value) {
Ext.ux.IconCombo.superclass.setValue.call(this, value);
this.setIconCls();
} // end of function setValue
});
// register xtype
Ext.reg('iconcombo', Ext.ux.IconCombo);
例子:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>IconCombobox</title>
<link rel="stylesheet" type="text/css" href="../../Client/Ext/resources/css/ext-all.css" />
<script type="text/javas
<script type="text/javas
<script type="text/javas
<style type="text/css">
.ux-flag-us {
background-image:url(Images/icon_package.gif) ! imp
}
.ux-flag-de {
background-image:url(Images/image_new.gif) ! imp
}
.ux-flag-fr {
background-image:url(Images/interface_browser.gif) ! imp
}
.ux-icon-combo-icon {
background-repeat: no-repeat;
background-position: 0 50%;
width: 18px;
height: 14px;
}
.ux-icon-combo-input {
padding-left: 25px;
}
.x-form-field-wrap .ux-icon-combo-icon {
top: 3px;
left: 5px;
}
.ux-icon-combo-item {
background-repeat: no-repeat ! imp
background-position: 3px 50% ! imp
padding-left: 24px ! imp
}
</style>
<script language="javas
Ext.BLANK_IMAGE_URL = '../../Client/images/s.gif';
Ext.on
var win = new Ext.Window({
title:'Icon Combobox',
width:400,
height:300,
layout:'form',
bodyStyle:'padding:10px',
labelWidth:70,
defaults:{anchor:'100%'},
items:[{
xtype:'iconcombo',
fieldLabel:'IconCombo',
store: new Ext.da
fields: ['countryCode', 'countryName', 'countryFlag'],
da
['US', 'United States', 'ux-flag-us'],
['DE', 'Germany', 'ux-flag-de'],
['FR', 'France', 'ux-flag-fr'],
['FR', 'France', '']
]
}),
valueField: 'countryCode',
displayField: 'countryName',
iconClsField: 'countryFlag',
triggerAction: 'all',
editable: false,
mode: 'local'
}]
});
win.show();
});
</script>
</head>
<body>
</body>
</html>