Extjs中的combobox的动态加载问题

boss0207 2007-10-25 01:12:13
想在Extjs的grid中添加combox,而这个combox是从数据库中动态取数据库里的东西,而不是静态的东西,请问怎么实现,最要有相关的代码和解释,主要就是用了ExtjsAPI里的哪些函数,具体点最好
...全文
12683 36 打赏 收藏 转发到动态 举报
写回复
用AI写文章
36 条回复
切换为时间正序
请发表友善的回复…
发表回复
lshq 2012-09-24
  • 打赏
  • 举报
回复
怎样动态改变proxy中的url值?4.0
hc459242451 2012-08-03
  • 打赏
  • 举报
回复
learning
qujianjiutian 2012-07-09
  • 打赏
  • 举报
回复
Ext.ux.form.ComboBox = Ext.extend(Ext.form.ComboBox, {
relationName : '',
pkFieldName : '',
bizObjClass : '',
action : '',
fieldLabel : '',
emptyText : '',
allowBlank : false,
mode : 'remote',
triggerAction : 'all',
// 当被选择时,显示全部的数据
displayField : '',
listWidth : 100,
width : 100,
valueField : '',
name : '',
forceSelection : false,
resizable : true,
typeAhead : true,
loadWhenRender : false,// 控件实例化后就开始搜索(如果selectFirstRow为true 则此设置无效)
selectFirstRow : false,// 默认选中第一条数据
totalRecords : 'total',
dataField:[],
// 'total'//查询结果记录数字段名
createStore : function() {
if (this.mode == 'remote') {
//debugger;

this.bizobj = eval('new ' + this.bizObjClass);
this.dataField.push(this.valueField);
this.dataField.push(this.displayField);
//this.saveInformation(this.bizobj);
this.store = new Ext.data.Store({
proxy : new CPC.ext.HttpProxy({
url : this.bizobj.getUrl()
}),
reader : new CPC.ext.BizObjReader({
record : this.relationName,
id : this.pkFieldName,
totalRecords : this.totalRecords
},this.dataField)
});

this.store.on('loadexception', this.onLoadError);
} else if (this.mode == 'local') {
this.displayField = 'text';
this.valueField = 'value', this.store = new Ext.ux.SimpleStore(
{
data : this.data
});

}
},
setCondition : function(obj) {
for (var i in obj) {
this.bizobj[i] = obj[i];
}
},
load : function(condition) {
//debugger;
if (this.mode == 'remote') {
this.store.removeAll();
this.bizobj = eval('new ' + this.bizObjClass);
if (condition) {
this.setCondition(condition);
}
this.saveInformation(this.bizobj);
this.store.load({
params : {
bizobj : this.bizobj,
action : this.action
}
});
if (this.selectFirstRow) {
this.store.on('load', function() {
Ext.each(this.store.data.items, function(
data) {
this.setValue(data
.get(this.valueField));
return false;

}, this);
}, this);
}
}
},
reload : function() {
if (this.mode == 'remote') {
this.store.load({
params : {
bizobj : this.bizobj,
action : this.action
}
});
}
},
reset : function() {
if (this.defaultValue) {
this.setValue(this.defaultValue);
} else {
Ext.ux.form.ComboBox.superclass.reset.call(this);
}
},
saveInformation : function(bizObj) {

},
initList : function() {
if (this.loadWhenRender == false)// 延时加载数据
this.load();
Ext.ux.form.ComboBox.superclass.initList.call(this, arguments);
},
getStore : function() {
return this.store;
},
isXType : function(xtype, shallow) {
if (typeof xtype == 'function') {
xtype = xtype.xtype;
} else if (typeof xtype == 'object') {
xtype = xtype.constructor.xtype;
}
return this.constructor.xtype == xtype;
},
destroy : function() {
this.bizobj = null;
this.store = null;
// 子类一定要调用父类的销毁方法
},
onDestroy : function name() {
this.destroy();
Ext.ux.form.ComboBox.superclass.onDestroy.call(this);
},
initComponent : function() {
this.init();
Ext.ux.form.ComboBox.superclass.initComponent.call(this);
},
setValue:function(value){
//如果远程数据还没有加载,在设值之前先加载一次
if ( this.store.getCount() == 0 ) {
this.store.on("load", function() {
Ext.ux.form.ComboBox.superclass.setValue.call(this, value);
}, this, {
single : false // 此处true、false有什么区别?
});
this.doQuery(this.allQuery, true);
} else {
Ext.ux.form.ComboBox.superclass.setValue.call(this, value);
}

},
init : function() {
//debugger;
if (this.selectFirstRow)
this.loadWhenRender = true;
this.createStore();
if (this.loadWhenRender) {// 默认选中首条数据
this.load();
}
// 子类一定要调用父类的初始化方法
}

});

Ext.reg('ecombobox', Ext.ux.form.ComboBox);
egewg3 2012-06-01
  • 打赏
  • 举报
回复
var areamanager_user_store = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url:'areamanager/searchUser'}),
reader: new Ext.data.JsonReader({
totalProperty: 'totalProperty',
root: 'root'
}, [
{name: 'userid'},
{name: 'username'},
])
});
areamanager_user_store.load();

new Ext.form.ComboBox({
fieldLabel: 'Management Level',
name:'group_id',
forceSelection: true,
listWidth: 150,
store: comboOptions,
valueField:'userid',
displayField:'username',
typeAhead: true,
mode: 'local',
triggerAction: 'all',
selectOnFocus:true,
allowBlank:false
});
zengjf1988 2012-04-11
  • 打赏
  • 举报
回复
for (var i = 0; i < dCfgSumStore; i++) {
var dCfgNameTemp = 'combobox' + i; //给每个ComBoBox不同的名字
// var storeNameTemp = 'dCfgVNNullStore' + i;
dCfgstoreArray[i].baseParams.dCfgName = dCfgVNotStore.getAt(i).get('dCfgName');
dCfgstoreArray[i].load();
dCfgNameTemp = new Ext.form.ComboBox({
name:'projectId',
id:'projectId' + i, //循环创建combobox时,id不能一样
allowBlank:false,
blankText:dCfgVNotStore.getAt(i).get('dCfgName')+'不允许为空',
fieldLabel:dCfgVNotStore.getAt(i).get('dCfgName'),
xtype:'combo',
store : dCfgstoreArray[i],
mode:'remote',
//pageSize:10,
//labelWidth:40,
displayField : 'dCfgValue',
valueField : 'dCfgValue',
forceSelection : true,
triggerAction : 'all',
editable : false
//listeners:{ beforequery :select_CfgValue}
});
zengjf1988 2012-04-11
  • 打赏
  • 举报
回复
for (var i = 0; i < dCfgSumStore; i++) {
var dCfgNameTemp = 'combobox' + i; //给每个ComBoBox不同的名字
// var storeNameTemp = 'dCfgVNNullStore' + i;
dCfgstoreArray[i].baseParams.dCfgName = dCfgVNotStore.getAt(i).get('dCfgName');
dCfgstoreArray[i].load();
dCfgNameTemp = new Ext.form.ComboBox({
name:'projectId',
id:'projectId' + i, //循环创建combobox时,id不能一样
allowBlank:false,
blankText:dCfgVNotStore.getAt(i).get('dCfgName')+'不允许为空',
fieldLabel:dCfgVNotStore.getAt(i).get('dCfgName'),
xtype:'combo',
store : dCfgstoreArray[i],
mode:'remote',
//pageSize:10,
//labelWidth:40,
displayField : 'dCfgValue',
valueField : 'dCfgValue',
forceSelection : true,
triggerAction : 'all',
editable : false
//listeners:{ beforequery :select_CfgValue}
});
rsredwolf 2012-03-22
  • 打赏
  • 举报
回复
有没有4.0的代码
josephSC 2012-03-22
  • 打赏
  • 举报
回复
var dataStore = combo.getStore();
dataStore.proxy.conn.url = 'new url';
combo.bindStore(dataStore);
jiangfullll 2012-03-16
  • 打赏
  • 举报
回复
var schemeStore = new Ext.data.Store({
proxy : new Ext.data.HttpProxy({
url : contextPath
+ '/confAveragefare/ConfAveragefare!getScheme.do'
}),
autoLoad : true,
reader : readerBase,
listeners : {
'load' : function() {
if (this.getCount() >= 2) {
schemeCombo.setValue(this.getAt(1).get('id'));
schemeCombo.fireEvent('select');
}
}
}
});

schemeCombo = new Ext.form.ComboBox({
fieldLabel : '方案选择',
hiddenName : 'schemeId',
triggerAction : 'all',
displayField : 'name',
store : schemeStore,
allowBlank : true,
typeAhead : true,
resizable : true,
valueField : 'id',
mode : 'remote',
anchor : '95%',
editable : false
})
jiangfullll 2012-03-16
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 umbrella_yxs 的回复:]

我写了一个,可以定向到service,但是不知道为什么取不出数据,哪个会的也帮我看下!!!
JScript code
var groupStore = new Ext.data.Store({
url: 'getGroupStore.action',
reader:_jsonGroupReader
});
……
[/Quote]

在comboBox中添加属性mode:'remote'就可以了
lin345521167 2012-03-16
  • 打赏
  • 举报
回复
学习一下!
浩瀚11 2011-09-07
  • 打赏
  • 举报
回复
学习中
canguangup 2011-06-10
  • 打赏
  • 举报
回复
很有用,学习。。。
q272416700 2011-05-13
  • 打赏
  • 举报
回复
学习中
toss3000 2011-05-04
  • 打赏
  • 举报
回复
学习中
LazyCoder 2011-03-23
  • 打赏
  • 举报
回复
谢谢 虽然帮助 不大
  • 打赏
  • 举报
回复
学习!!!!!!!!!!!!!
hncdzyl 2011-02-12
  • 打赏
  • 举报
回复
每天回帖即可获得10分可用分!小技巧
greatmind829 2011-02-12
  • 打赏
  • 举报
回复
跑跑鱼 2010-08-28
  • 打赏
  • 举报
回复
每天回帖即可获得10分可用分!小技巧
加载更多回复(16)
Edit Grid限制编辑 ExtJS 4 DirectStore post参数的变化以及应对方法 ExtJS 4 实例之数据包 ExtJS 4动态加载的路径设置 Extjs4 API文档阅读(一)——类系统(Class System) Extjs4 API文档阅读(三)——布局和容器 Extjs4 API文档阅读(二)——MVC构架(上) Extjs4 API文档阅读(二)——MVC构架(下) Extjs4 API文档阅读(四)——Data ExtJS4 Grid组件 Extjs4 TreeGrid Extjs4 TreePanel实例 ExtJs4 动态加载 Extjs4 带复选框的树(Checkbox tree) Extjs4 新的布局方式 Extjs4 锁定表头(Locking Grid)功能 Extjs4.0 MVC实例 Extjs4.0动态填充combobox数据 Extjs4up()和down()的用法 ExtJS4学习笔记(一)---window的创建 ExtJS4学习笔记(七)---带搜索的Grid(SearchGrid) ExtJS4学习笔记(三)---VBox的使用 ExtJS4学习笔记(九)---ExtJS4 EditGrid(可编辑的Grid) ExtJS4学习笔记(二)---HBox的使用 ExtJS4学习笔记(五)---Grid分页 ExtJS4学习笔记(八)---Grid多选 全选 ExtJS4学习笔记(六)---多表头Grid ExtJS4学习笔记(十)---ExtJS4图片验证码的实现 ExtJS4学习笔记(十一)---TabPanel ExtJS4学习笔记(十三)---上传文件(upload) ExtJS4学习笔记(十二)---选项卡(tabs) ExtJS4学习笔记(十五)---Ext.data.Model ExtJS4学习笔记(十六)---Combobox三级联动 ExtJS4学习笔记(十四)--- ComponentQuery ExtJS4学习笔记(四)---Grid的使用 Extjs4开发笔记(三)——菜单的实现 Extjs4开发笔记(二)——框架的搭建 Extjs4开发笔记(五)——动态grid Extjs4开发笔记(四)——实现登录功能 Extjs4开发笔记(一)——准备工作 关于Extjs4开发笔记(二)的补充说明 在Extjs4应用使用Ext.Loader ======================================= 11条jquery常用技巧和方法整理列表 8个超棒的学习jQuery的网站 JQuery 1.5 getJSON 的使用 JQuery AJAX提交文乱码的解决方案 Jquery css函数用法 JQuerygetJSON的使用方法 Jquery显示隐藏的实现代码分析 JQuery全选功能的实现 JQuery特效——下拉菜单 JQuery系列教程之XPath选择符 JQuery系列教程之选择符 JQuery自动缩放页面的图片 JQuery获取浏览器的高度和宽度 jquery获得和设置下拉框值的代码 基于jquery的跨域调用文件 ================================= 7款强大的Javascript网格插件 Javascript 汉字编码转换 Javascript 面向对象之封装 Javascript 面向对象之构造函数的继承 Javascript 面向对象之非构造函数的继承 JavaScript对象与继承教程之内置对象(下) JavaScript对象及继承教程(上) javascript正则表达式(一) javascript正则表达式(二) JavaScript的10种跨域共享方法 JavaScript类型总览 JavaScript获取文本框光标的像素位置 js函数match、exec、test、search、replace、split使用介绍 技巧:Javascript使用隐藏的new来创建对象 禁止页面全选复制,兼容多种浏览器

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧