通过前面的资料,我需要做一个加载部门的领导的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']]