ExtJS:如何设置组合框id?
我有个小问题。在我的应用程序中,我总是构建两个链接的组合框-国家和城镇(然后选择国家/地区-城镇开始加载)。所以我想-mbe写一个构造函数并最小化我的代码?好的,我做到了。但我遇到了一个问题:我在页面上有2-3个链接的组合框,当我在第二个组合国家中选择时,数据(城镇)在第一个组合中加载,因为它具有相同的id。好的-现在我尝试将参数id带到构造函数中,但它不起作用。如何设置combobox的id,然后创建一个对象 乡村组合ExtJS:如何设置组合框id?,extjs,combobox,linked-list,set,Extjs,Combobox,Linked List,Set,我有个小问题。在我的应用程序中,我总是构建两个链接的组合框-国家和城镇(然后选择国家/地区-城镇开始加载)。所以我想-mbe写一个构造函数并最小化我的代码?好的,我做到了。但我遇到了一个问题:我在页面上有2-3个链接的组合框,当我在第二个组合国家中选择时,数据(城镇)在第一个组合中加载,因为它具有相同的id。好的-现在我尝试将参数id带到构造函数中,但它不起作用。如何设置combobox的id,然后创建一个对象 乡村组合 comboCountryClass = Ext.extend(Ext.fo
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\u name\u id:'townFormSearch'})
新comboCountryClass({town\u name\u id:'townFormSearch'})我遵守规则:“永远不要使用硬编码id”。您可以使用
Ext.id(null,'someTextString')
当您使用唯一ID时,您将承担更多的簿记工作,但您不会遇到上面提到的问题
有时,我在对象中本地存储唯一ID,然后在必要时引用该实例变量
this.idForCombo = Ext.id( null, 'someTextString' );
var myCmp = new SomeConstructor({
id: this.idForCombo,
...more stuff });
您可以通过执行以下操作来设置组件的id: 新的comboTownClass({id:'townComboId'}); 新的comboCountryClass({id:'countryComboId'}) 您可以指定默认id,当您在配置参数中传递id时,它将覆盖默认值
虽然我同意@Upper Stage,但您应该尝试限制表单中硬编码id值的数量-您可以改为使用表单名称获取表单元素。请参阅此屏幕广播:了解(不)使用组件id的一些提示。在您的解决方案中(本地-我有一个.js文件中的代码)正确创建具有唯一id的comboTown,但是乡村组合似乎根本没有这个id。这里可能有什么问题?我看不出这个.town\u name\u id设置在哪里。所以,我不能确定[id:this.town_name_id|u'youuu']是否如您所期望的那样工作。我也看不到您在哪里使用这个ID。(还应该在您的组合框构造函数中检查这个ID的范围-可能是确定的。)
this.idForCombo = Ext.id( null, 'someTextString' );
var myCmp = new SomeConstructor({
id: this.idForCombo,
...more stuff });