通过前面的资料,我需要做一个加载部门的领导的combox,而且用到很多地方,于是自定义了一个combox组件代码如下:
LeaderCombox = Ext.extend(Ext.form.ComboBox, {
fieldLabel : 'Label',
fieldLabel : "审核人",
width : 135,
mode : 'local', // 直接从本地获得数据(已通过nativeStore.load()将数据加载到本地,不需要用
// remote 再从服务器获取)
name : "leader",
// hiddenName : "enativeplace", //通过隐藏着值将value的值传提交到后台
valueField : 'id',
displayField : 'name',
triggerAction : "all", // 设置下拉选择,如果没设置,选中一个之后,不能再重选其他的选项
editable : false,
emptyText : "请选择审核人..",
url:null,
initComponent : function() {
var store = new Ext.data.Store({
scope:this,
proxy : new Ext.data.HttpProxy({
scope:this,
url : this.url
}),
reader : new Ext.data.ArrayReader({}, [{
name : 'id'
}, {
name : 'name'
}])
})
store.load();
this.store = store;
LeaderCombox.superclass.initComponent.call(this);
}
});
使用的时候只需要如下方式即可,这样在每个需要的地方调用即可,很方便
new LeaderCombox({url:'combox.jsp'})
combox。jsp返回的数据形式如下:
[ ['3', 'Three'], ['4', 'Four'], ['5', 'Five'],['6', 'Six'], ['7', 'Seven'], ['8', 'Eight'], ['9', 'Nine']]
LeaderCombox = Ext.extend(Ext.form.ComboBox, {
fieldLabel : 'Label',
fieldLabel : "审核人",
width : 135,
mode : 'local', // 直接从本地获得数据(已通过nativeStore.load()将数据加载到本地,不需要用
// remote 再从服务器获取)
name : "leader",
// hiddenName : "enativeplace", //通过隐藏着值将value的值传提交到后台
valueField : 'id',
displayField : 'name',
triggerAction : "all", // 设置下拉选择,如果没设置,选中一个之后,不能再重选其他的选项
editable : false,
emptyText : "请选择审核人..",
url:null,
initComponent : function() {
var store = new Ext.data.Store({
scope:this,
proxy : new Ext.data.HttpProxy({
scope:this,
url : this.url
}),
reader : new Ext.data.ArrayReader({}, [{
name : 'id'
}, {
name : 'name'
}])
})
store.load();
this.store = store;
LeaderCombox.superclass.initComponent.call(this);
}
});
使用的时候只需要如下方式即可,这样在每个需要的地方调用即可,很方便
new LeaderCombox({url:'combox.jsp'})
combox。jsp返回的数据形式如下:
[ ['3', 'Three'], ['4', 'Four'], ['5', 'Five'],['6', 'Six'], ['7', 'Seven'], ['8', 'Eight'], ['9', 'Nine']]
- /**
- * 韩飞
- *
- * @class TreeSelector
- * @extends Ext.form.ComboBox
- */
- TreeSelector = Ext.extend(Ext.form.ComboBox, {
- /**
- * 回调函数,用于传递选择的id,text属性
- *
- * @type
- */
- callback : Ext.emptyFn,
- store : new Ext.data.SimpleStore({
- fields : [],
- data : [[]]
- }),
- editable : false,
- mode : 'local',
- emptyText : "请选择部门",
- allowBlank : false,
- blankText : "必须输入!",
- triggerAction : 'all',
- maxHeight : 200,
- anchor : '95%',
- displayField : 'text',
- valueField : 'id',
- tpl : "<tpl for='.'><div style='height:200px'><div id='tree'></div></div></tpl>",
- selectedClass : '',
- onSelect : Ext.emptyFn,
- /**
- * 根的名字
- *
- * @type String
- */
- rootText : '组织机构',
- /**
- * 树的请求地址
- *
- * @type String
- */
- treeUrl : 'system/organization/loadOrganizationTrees.action',
- tree : null,
- initComponent : function() {
- this.tree = new Ext.tree.TreePanel({
- height : 200,
- scope : this,
- autoScroll : true,
- split : true,
- root : new Ext.tree.AsyncTreeNode({
- expanded : true,
- id:'o',
- text : this.rootText
- }),
- loader : new Ext.tree.TreeLoader({
- url : this.treeUrl
- }),
- rootVisible : true
- // ,
- /*
- * listeners : { scope : this, 'click' : function(node) {// 单击事件
- * if (node.id != null && node.id != '') {
- *
- * this.callback.call(this, node.id, node.text);
- *
- * this.collapse();
- * } } }
- */
- });
- var c = this;
- /**
- * 点击选中节点并回调传值
- */
- this.tree.on('click', function(node) {
- if (node.id != null && node.id != '') {
- if (node.id != 'o') {
- c.callback.call(this, node.id, node.text);
- c.collapse();
- }else{
- Ext.Msg.alert("提示","此节点无效,请重新选择!")
- }
- }
- })
- this.on('expand', function() {
- this.tree.render('tree');
- this.tree.expandAll();
- });
- TreeSelector.superclass.initComponent.call(this);
- }
- })