【发布时间】:2010-09-21 12:47:58
【问题描述】:
我有一个小问题。在我的应用程序中,我总是构建两个链接的组合框 - 国家和城镇(然后选择国家 - 城镇开始加载)。所以我想 - mbe 编写一个构造函数并最小化我的代码?好的,我做到了。但我遇到了一个问题:我在页面上有 2-3 个这样的链接组合框,当我在第二个组合国家/地区选择时,数据(城镇)在第一个组合中加载,因为它具有相同的 id。好的 - 现在我尝试将参数 id 传递给构造函数,但它没有用。如何设置组合框的 id 然后我创建一个对象?
国家组合
comboCountryClass = Ext.extend(Ext.form.ComboBox, {
fieldLabel: 'country',
anchor: '95%',
lazyRender:true,
store:new Ext.data.Store({
proxy: new Ext.data.HttpProxy(
{url: '../lib/getRFB.php?rfb_type=countrys',
method: 'GET'}
),
reader: countryReader,
autoLoad: true
}),
displayField:'country_name',
valueField:'country_id',
triggerAction:'all',
mode:'local',
listeners:{
select:{
fn:function(combo, value) {
var modelCmp = Ext.getCmp(this.town_name_id);
alert(this.town_name_id);
modelCmp.setValue('');
modelCmp.getStore().proxy.setUrl('../lib/getRFB.php');
modelCmp.store.reload({
params: { 'country_id': this.getValue(),rfb_type: 'towns' }
});
}
}
},
hiddenName:'country_id',
initComponent: function() {comboCountryClass.superclass.initComponent.call(this);}})
和城镇组合
comboTownClass = Ext.extend(Ext.form.ComboBox, {
fieldLabel:'town',
displayField:'town_name',
valueField:'town_id',
hiddenName:'town_id',
anchor: '95%',
id:this.town_name_id || 'youuuu',
store: new Ext.data.Store({
proxy: new Ext.data.HttpProxy(
{url: 'lib/handlers/orgHandler.php?action=read&towns=true',
method: 'GET'}
),
reader: townReader
}),
triggerAction:'all',
mode:'local',
initComponent: function() {comboTownClass.superclass.initComponent.call(this);}})
新的 comboTownClass({town_name_id:'townFormSearch'})
新的comboCountryClass({town_name_id:'townFormSearch'})
【问题讨论】:
-
观看此截屏视频:tdg-i.com/392/ext-js-screencast-the-dangers-of-ext-getcmp 了解有关(不)使用组件 ID 的一些提示。
标签: extjs combobox linked-list set