我希望每次点击下拉框的时候,就去后台查一下数据,我想实现这种效果:点击下拉框,取到内容后去后台查询它的子级显示在 textfiled中,这个像省市级联,但是网上的都是Store绑定子级下拉框,而我只想取一个子级,显示在text中。//数据源
var cstores=new Ext.data.Store({
url: '<%=Url.Action("LoadCode", "Organization") %>',
reader: new Ext.data.JsonReader({
id: 'Id'
}, ['Id','OrganizationName','Code']),
remoteSort: false
});
//下级查询数据 5/26 2011 14:30
var childStores = new Ext.data.Store({
url: '<%=Url.Action("LoadCode", "Organization" new { Code = Code } ) %>',
reader: new Ext.data.JsonReader({
id: 'Id'
}, ['Id','Code']),
remoteSort: false
}); var txtP=new Ext.form.ComboBox({
fieldLabel: '<font color="red">*</font>上级编号',
store: cstores,
name: 'CodeStr',
hiddenName: 'CodeStr',
valueField: 'Code',
displayField: 'OrganizationName',
typeAhead: true,
mode: 'remote',
triggerAction: 'all',
emptyText: '---请选择上级---',
listeners:{
select : function(txtP,newValue,oldValue)
{
childStores.proxy= new Ext.data.HttpProxy({url: '<%=Url.Action("LoadCode", "Organization" new { Code = '+newValue+' } ) %>'});
childStores.load(); //加载
}
},
selectOnFocus: true,
allowBlank: false,
width: 200
});
var cstores=new Ext.data.Store({
url: '<%=Url.Action("LoadCode", "Organization") %>',
reader: new Ext.data.JsonReader({
id: 'Id'
}, ['Id','OrganizationName','Code']),
remoteSort: false
});
//下级查询数据 5/26 2011 14:30
var childStores = new Ext.data.Store({
url: '<%=Url.Action("LoadCode", "Organization" new { Code = Code } ) %>',
reader: new Ext.data.JsonReader({
id: 'Id'
}, ['Id','Code']),
remoteSort: false
}); var txtP=new Ext.form.ComboBox({
fieldLabel: '<font color="red">*</font>上级编号',
store: cstores,
name: 'CodeStr',
hiddenName: 'CodeStr',
valueField: 'Code',
displayField: 'OrganizationName',
typeAhead: true,
mode: 'remote',
triggerAction: 'all',
emptyText: '---请选择上级---',
listeners:{
select : function(txtP,newValue,oldValue)
{
childStores.proxy= new Ext.data.HttpProxy({url: '<%=Url.Action("LoadCode", "Organization" new { Code = '+newValue+' } ) %>'});
childStores.load(); //加载
}
},
selectOnFocus: true,
allowBlank: false,
width: 200
});
url: '<%=Url.Action("LoadCode", "Organization" new { Code = Code } ) %>',
reader: new Ext.data.JsonReader({
id: 'Id'
}, ['Id','Code']),
remoteSort: false,
load:function(store,rcds,opts){//添加load事件,在这个事件中设置textfiled的值就行了。
if(store.getTotalCount()>0) textfiledExtElement.setValue(rcds[0].get("id"));//注意修改textfiledExtElement为你的变量名称
else alert('没有数据')
}
});